Problem displaying time for past dates

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?

1 Like

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!

3 Likes

Thank you for the clarification and the reference to the package. It does in fact solve my problem, as you can see on this ellie. Thanks again :slight_smile:

1 Like

As someone doing more the ops than dev from devops I would still prefer the use of the browsers API when you need to support only newer browsers, because I have often the situation of an old running application where no developers available anymore. http://htmlpreview.github.io/?https://github.com/hans-helmut/elm-timei18n/blob/master/index.html

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.