time
time copied to clipboard
Time.getZoneName incorrectly handles missing Intl support in ie11
Using Time.getZoneName in ie11 results in an invalid state for ZoneName. Instead of falling back to the timezone offset, it holds undefined in the Name variant.
The kernel code seems to expect a failure when Intl isn't fully supported, but ie11 just gives undefined.
var name = __Time_Name(Intl.DateTimeFormat().resolvedOptions().timeZone); results in __Time_Name(undefined) rather than throwing an exception which could be caught and used to find an offset.
module Main exposing (main)
import Browser
import Html exposing (Html, div, span, text)
import Time exposing (ZoneName(..))
import Task
type alias Model =
Maybe ZoneName
initialModel : () -> (Model, Cmd Msg)
initialModel () =
(Nothing, Task.perform Zone Time.getZoneName)
type Msg
= Zone ZoneName
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Zone zone ->
(Just zone, Cmd.none)
view : Model -> Html Msg
view model =
div []
[ span []
[ case model of
Just (Name zoneName) ->
text ("Timezone name: [" ++ zoneName ++ "]")
Just (Offset offset) ->
text ("Timezone offset: [" ++ String.fromInt offset ++ "]")
Nothing ->
text "no timezone result"
]
]
main : Program () Model Msg
main =
Browser.element
{ init = initialModel
, view = view
, update = update
, subscriptions = always Sub.none
}