Change how timezone aware datetimes with UTC tz are converted to datetime string
Diff of User Interface
Old behavior:
passing a timezone aware datetime from the UTC zone to some of the request constructors resulted in malformed datetime strings, e.g: 2022-06-01T01:00:00+00:00Z - i.e. strings that have BOTH +00:00 and Z at the end.
At the root of it was value.utcoffset() >> timedelta(hours=0) evaluating as False even though there is a defined offset here:
def _datetime_to_rfc3339(value: datetime) -> str:
"""Converts the datetime to an RFC3339 string"""
iso = value.isoformat()
if not value.utcoffset():
# rfc3339 needs a Z if there is no timezone offset
iso += 'Z'
return iso
New behavior:
The Z is tagged on only if the utcoffset() is None.
When the TZ is UTC the dt string is:
2022-06-01T01:00:00+00:00
The previous test setup for timezone aware datetimes obfuscated this bug, so I changed the tests as well.
PR Checklist:
[x] This PR is as small and focused as possible
[x] If this PR includes proposed changes for inclusion in the changelog, the title of this PR summarizes those changes and is ready for inclusion in the Changelog.
[x] I have updated docstrings for function changes and docs in the 'docs' folder for user interface / behavior changes
[x] This PR does not break any examples or I have updated them
Proposed Changes:
For inclusion in changelog (if applicable):
1.
Not intended for changelog:
Diff of User Interface
Old behavior: passing a timezone aware datetime from the UTC zone to some of the request constructors resulted in malformed datetime strings, e.g:
2022-06-01T01:00:00+00:00Z
- i.e. strings that have BOTH+00:00
andZ
at the end.At the root of it was
value.utcoffset()
>>timedelta(hours=0)
evaluating as False even though there is a defined offset here:New behavior: The Z is tagged on only if the utcoffset() is None.
When the TZ is UTC the dt string is:
2022-06-01T01:00:00+00:00
The previous test setup for timezone aware datetimes obfuscated this bug, so I changed the tests as well.
PR Checklist:
(Optional) @mentions for Notifications: