views: _api_occurrences: Support handling of timezone-aware datetime … - #553
Conversation
…strings (2022-01-01T01:00:00+01:00).
|
@daym Have you been using this with recurring events at all? I had applied a similar change, and whenever Generates an Just for anyone in the future, I ended up dealing with it by using the offset to calculate UTC and then replacing the tzinfo with UTC. So the code in the PR looks like this in my environment: |
By now I have a lot more changes in https://github.com/daym/django-scheduler --and that I do use with recurrent events in production (using fullcalendar in Javascript). The ideas neccessary to fix it are the following (already used by django-scheduler but I had to find out):
I'll eventually add more PRs here about it. More details about timezones and datetime: https://blog.ganssle.io/articles/2018/03/pytz-fastest-footgun.html - all these things are not at all incorporated into this PR (it would require Python >= 3.6 if we did).
Yeah :( See above. |
|
@daym I'm taking a look to it now. |
- Fix Black formatting in views.py (blank lines around nested function defs) - Update test_occurrences_api_fails_with_incorrect_date_string_formats to use genuinely invalid date strings since dateutil.parser.parse is more permissive than the old strptime-based approach - Fix Black formatting in test_templatetags.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…strings (2022-06-07T02:03:04+05:00).
Previously, such strings would fail with
ValueErrorunconverted 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:
Additionally, since now it's possible for the
convertfunction to return a datetime withtzinfothat is set, make sure not to try to add another (conflicting) tzinfo in that case.