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

datetime: convert timestamptz to local timezone #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TheJJ
Copy link

@TheJJ TheJJ commented Feb 22, 2023

This fixes MagicStack/asyncpg#1006 :)

@TheJJ
Copy link
Author

TheJJ commented Apr 8, 2023

can this please be merged?

@elprans
Copy link
Member

elprans commented Aug 17, 2023

This is technically a backwards-incompatible change as clients might stringify returned datetime objects or otherwise rely on the timezone being UTC. I would play it safe and add a configuration knob to CodecContext.

@TheJJ
Copy link
Author

TheJJ commented Aug 21, 2023

Would you be willing to implement that? Or is there another way of defaulting timezone-including datetime objects?
As the timestamptz does include the timezone, returning it as UTC seems a bug to me.

timedelta(0, seconds, microseconds))
# convert to current system timezone
return dt.astimezone()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is almost certainly not what you want. astimezone() creates a broken fixed-offset timezone object that does not do DST. This exists because python did not use to have a proper timezones implementation, but it has zoneinfo now. A better way would be to have a timezone object in settings, defaulting to UTC, and do astimezone(settings.timezone) here.

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.

Database timezone ignored for timestamptz
3 participants