Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dict encoding for timezone aware datetimes #468

Conversation

semicolonTransistor
Copy link
Contributor

See #467

When a timezone-aware datetime object is encoded via _Timestamp.timestamp_to_json its timezone information is stripped and it is encoded as if it is UTC. This caused the decoded datetime from the dict to refer to a different point in time from the original datetime. Since the JSON serialization routine calls the dict encode routine this problem also affects JSON.
I added a check in _Timestamp.timestamp_to_json that converts timezone-aware datetime object to UTC before stripping the timezone and encoding. I also added some tests to check that timezone-aware datetime objects are encoded and decoded correctly. Naive datetime objects are still treated as UTC which is unchanged.

@Gobot1234
Copy link
Collaborator

Thanks for all this work

@Gobot1234 Gobot1234 changed the title Fix dict encoding for timezone aware datetime object Fix dict encoding for timezone aware datetimes Apr 13, 2023
@Gobot1234 Gobot1234 merged commit 2b41383 into danielgtaylor:master Apr 13, 2023
bbonenfant pushed a commit to pachyderm/python-betterproto that referenced this pull request Jan 23, 2024
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
bbonenfant pushed a commit to pachyderm/python-betterproto that referenced this pull request Jan 23, 2024
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants