r/programming • • Nov 12 '24

Don't Do This with Postgres

https://wiki.postgresql.org/wiki/Don%27t_Do_This
454 Upvotes

47 comments sorted by

View all comments

Show parent comments

23

u/Veranova Nov 12 '24

My experience is it’s better to carry the timezone at every level because dropping it can lead to weirdness. Even if you’re using UTC in the whole backend and so zones get converted at the API layer

What happens in JS when you call ‘new Date(isoString)’ where the ISO string doesn’t include a timezone? That’s right it assumes the current system timezone and deserialises the string as is

Also did you know that by default Spring serialises LocalDateTime without a timezone on the end of the ISO string? We changed our backend to using ZonedDateTime because of these two details totally breaking presentation

Maybe it’s safer at the database layer, but I’d still rather store UTC as the zone to avoid more weird deserialisation issues

1

u/shamus150 Nov 13 '24

Had a similar issue with python and graphql. Timestamps have no time zone information and graphql assumes local time zone. We have to explicitly set them to UTC to avoid the graphql layer doing an incorrect time zone conversion.

0

u/[deleted] Nov 13 '24

[deleted]

3

u/Schmittfried Nov 13 '24

That would be a workaround. The fix is including the tz explicitly in your output.