I’m working on an application that hosts videos, and each video has an upload date and time (stored in UTC). I’d like to format this date and time according to the user’s timezone. For this, I use the elm/time package with Time.here to get the user zone and Time.toHours to display the hour corresponding to an upload time.
Last week we had a DST change, and as a result Time.here is not giving the same zone offset and all displayed dates have been shifted by 1h. I want to display the time from the timezone where the user was
at that moment. How can I do that? For example, in JS, if you ask the timezone offset of dates, in France, you get this:
> new Date("2020-10-15T19:00:00.000Z").getTimezoneOffset()
-120
> new Date("2020-10-27T20:00:00.000Z").getTimezoneOffset()
-60
In France, both represent 21:00, but using Time.toHours with the zone returned by Time.here displays 20 for the first one, and 21 for the second, as you can see in this ellie. How would you go about displaying 21 for both in Elm?
There’s a short note in the time documentation for here that says that it only gives the current offset because there isn’t good browser support for the entire timezone data. So to get the data about what the offset was for all points in time, you can use the Timezone-data package. This package bundles up all of the the IANA database so you can get correct timezone information for any zone at any point in time. You’ll want to use the getZone function to get the information for the user. (it also supports getting a specific timezone by name if you need that). I hope it works out for you!