time icon indicating copy to clipboard operation
time copied to clipboard

Time.getZoneName incorrectly handles missing Intl support in ie11

Open stephenreddek opened this issue 5 years ago • 0 comments

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.

Screen Shot 2020-12-15 at 14 23 39 PM

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.

Screen Shot 2020-12-15 at 14 05 43 PM

SSCCE ellie gist raw:

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
        }

stephenreddek avatar Dec 15 '20 20:12 stephenreddek