Handling when urldecode has removed +.

This commit is contained in:
Roland 2023-02-25 19:30:52 -07:00
parent 2b7f667699
commit 1d97f0e3a6
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
2 changed files with 12 additions and 0 deletions

View file

@ -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)

View file

@ -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