massivefermion / birl

datetime handling for gleam
https://hex.pm/packages/birl
Apache License 2.0
54 stars 9 forks source link

Time Zones do not Account for DST #15

Open jrstrunk opened 3 months ago

jrstrunk commented 3 months ago

The following code

birl.from_unix(1_711_456_116) |> birl.set_timezone("America/New_York") |> birl.to_iso8601 |> io.debug

produces 2024-03-26T07:28:36.000-05:00 when it should produce 2024-03-26T08:28:36.000-04:00 because America/New_York is in EDT time right now, which has the offset of -04:00. Between sometime in March and sometime in November each year in America the timezone offset values changes to an hour ahead because of Daylight Saving Time.

jrstrunk commented 3 months ago

In the meantime I have adjusted my database to store formatted local time instead of timestamps so that I just don't have to worry about converting between them. I was able to do this comfortably because my project is tied to a local physical location, so data always originates from and is consumed in the same timezone.

Birl being Gleam native is really nice, but with the complexity of time zones, maybe it does not make sense for Birl to support them when the ecosystem project is still so new (I'm talking about named time zones, like "America/New_York", not offset times). Maybe a package should be created that is wrapper for an Erlang lib that handles getting the offset from named time zones, then it could be used with Birl once the proper offset is known.

massivefermion commented 3 months ago

yeah, I've been trying to solve this issue for a while, but I just couldn't find enough free time to do it. Your suggestion makes sense, though I just don't think removing part of the functionality is the right thing to do here. I think it makes more sense to just warn the users that this problem exists so that if a user determines that this issue won't affect them, they can still use the feature. Thanks for the issue

jrstrunk commented 2 months ago

Yeah now that the package is v1, I agree we can't just remove it. Maybe adding gleam's deprecated attribute to it would do the trick.