mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-26 09:56:17 -05:00
Handling when urldecode has removed +.
This commit is contained in:
parent
2b7f667699
commit
1d97f0e3a6
2 changed files with 12 additions and 0 deletions
|
|
@ -42,6 +42,9 @@ def strftime(dt: datetime) -> str:
|
|||
|
||||
|
||||
def strptime(dt: str) -> datetime:
|
||||
if isinstance(dt, str) and dt.endswith(' 00:00'):
|
||||
# URL decoding removed +
|
||||
dt = f'{dt[:26]}+00:00'
|
||||
return datetime.fromisoformat(dt).astimezone(pytz.UTC)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import pytest
|
|||
import pytz
|
||||
from sqlalchemy import Column, Integer
|
||||
|
||||
from wrolpi import dates
|
||||
from wrolpi.common import Base
|
||||
from wrolpi.dates import TZDateTime, timedelta_to_timestamp
|
||||
from wrolpi.db import get_db_session, get_db_curs
|
||||
|
|
@ -70,3 +71,11 @@ def test_TZDateTime(test_session):
|
|||
])
|
||||
def test_timedelta_to_timestamp(td, expected):
|
||||
assert timedelta_to_timestamp(td) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('dt,expected', [
|
||||
('2023-02-26T02:27:26.408944+00:00', datetime(2023, 2, 26, 2, 27, 26, 408944, tzinfo=pytz.UTC)),
|
||||
('2023-02-26T02:27:26.408944 00:00', datetime(2023, 2, 26, 2, 27, 26, 408944, tzinfo=pytz.UTC)),
|
||||
])
|
||||
def test_strptime(dt, expected):
|
||||
assert dates.strptime(dt) == expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue