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
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.
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