You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Time.here produces a timezone with fixed offset. Since time zones are only required when formatting times for humans this is useless for all values other than "right now", because we can't be sure that the offset "here" doesn't change in the next five minutes.
I want to display a time in the future in the browser's local time zone (in my case, Europe/Berlin). This seems to be impossible to do correctly. I understand that browsers don't have an API that allows to compute local times in arbitrary locations, but it is no problem to compute local times in the browser's configured location:
// Noon on December 1st 2020 in Berlin
new Date(1606820400000).getHours() == 12
I would expect Time.millisToPosix 1606820400000 |> Time.toHour tz (where tz is the Zone produced by Time.here) to return 12, but it returns 13 instead. I understand that Time.here produces a Time.Zone with a fixed UTC offset (currently +2 here in Berlin), but here where I am the offset isn't fixed (the offset is going to be +1 in December)! So Time.here is useless for any time on the other side of a DST change.
To summarize, Time.here is at the very least a misnomer (it's more like hereAndNow), but ideally it would produce correct local times for all inputs, which is possible to do with plain JavaScript as demonstrated above.
Complete program:
moduleMainexposing (main)
importBrowserimportHtmlexposing (p, text)
importTaskimportTimetype Msg=GotTZTime.Zonemain =Browser.element
{ init = init
, update = update
, view = view
, subscriptions = always Sub.none
}init:()-> ( Time.Zone, CmdMsg )
init _ =(Time.utc,Task.perform GotTZTime.here )update msg _ =case msg ofGotTZ tz ->( tz,Cmd.none )view tz =let
hour =Time.millisToPosix 1606820400000|>Time.toHour tz
-- Returns 13 at the time of writing (August 2020) in Europe/Berlin, but expected it to be 12.in
p [][ text <|String.fromInt hour ]
The text was updated successfully, but these errors were encountered:
@tsmanuelanton, I don't recall what I ended up doing (I don't even know anymore what I was working on, exactly). If I had to guess: I probably used moment.js to do the formatting.
Time.here produces a timezone with fixed offset. Since time zones are only required when formatting times for humans this is useless for all values other than "right now", because we can't be sure that the offset "here" doesn't change in the next five minutes.
I want to display a time in the future in the browser's local time zone (in my case, Europe/Berlin). This seems to be impossible to do correctly. I understand that browsers don't have an API that allows to compute local times in arbitrary locations, but it is no problem to compute local times in the browser's configured location:
I would expect
Time.millisToPosix 1606820400000 |> Time.toHour tz
(where tz is the Zone produced by Time.here) to return 12, but it returns 13 instead. I understand that Time.here produces a Time.Zone with a fixed UTC offset (currently +2 here in Berlin), but here where I am the offset isn't fixed (the offset is going to be +1 in December)! So Time.here is useless for any time on the other side of a DST change.To summarize, Time.here is at the very least a misnomer (it's more like hereAndNow), but ideally it would produce correct local times for all inputs, which is possible to do with plain JavaScript as demonstrated above.
Complete program:
The text was updated successfully, but these errors were encountered: