django-scheduler
django-scheduler copied to clipboard
views: _api_occurrences: Support handling of timezone-aware datetime …
…strings (2022-06-07T02:03:04+05:00).
Previously, such strings would fail with ValueError
unconverted data remains: +01:00
.
This patch changes it so it uses dateutil.parser.parse. The latter can parse all of the following and return a non-surprising result:
>>> dateutil.parser.parse('2020-01-01')
datetime.datetime(2020, 1, 1, 0, 0)
>>> dateutil.parser.parse('2020-01-01 05:42')
datetime.datetime(2020, 1, 1, 5, 42)
>>> dateutil.parser.parse('2020-01-01T05:42')
datetime.datetime(2020, 1, 1, 5, 42)
>>> dateutil.parser.parse('2020-01-01T05:42:00')
datetime.datetime(2020, 1, 1, 5, 42)
>>> dateutil.parser.parse('2020-01-01T05:42:00+01:00')
datetime.datetime(2020, 1, 1, 5, 42, tzinfo=tzoffset(None, 3600))
Additionally, since now it's possible for the convert
function to return a datetime with tzinfo
that is set, make sure not to try to add another (conflicting) tzinfo in that case.