Better timezone

This commit is contained in:
Thomas Forgione 2020-10-28 16:57:08 +01:00
parent e5c9bde291
commit a6c651bdd2
2 changed files with 18 additions and 4 deletions

View File

@ -15,6 +15,7 @@
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"jims/html-parser": "1.0.0",
"justinmimbs/timezone-data": "3.0.3",
"mdgriffith/elm-ui": "1.1.8",
"rtfeldman/elm-iso8601-date-strings": "1.1.3"
},

View File

@ -10,6 +10,7 @@ import Http
import Ports
import Task
import Time
import TimeZone
import Twitch
import Url
@ -44,6 +45,7 @@ type Msg
| UrlReceived Url.Url
| UrlRequested Browser.UrlRequest
| SizeReceived Int Int
| TimeZoneReceivedResult (Result TimeZone.Error ( String, Time.Zone ))
| TimeZoneReceived Time.Zone
| HoverPlaylist Twitch.Playlist
| HoverVideo Twitch.Video
@ -55,7 +57,9 @@ init : { width : Int, height : Int } -> Url.Url -> Nav.Key -> ( FullModel, Cmd M
init { width, height } url key =
( Unloaded (Element.classifyDevice { width = width, height = height }) url key Time.utc
, Cmd.batch
[ Task.perform TimeZoneReceived Time.here
[ Task.attempt TimeZoneReceivedResult TimeZone.getZone
-- Task.perform TimeZoneReceived Time.here
, Twitch.fetchPlaylists resultToMsg
]
)
@ -88,6 +92,18 @@ update msg model =
( TimeZoneReceived z, Unloaded d u k _ ) ->
( Unloaded d u k z, Cmd.none )
( TimeZoneReceived z, Loaded m ) ->
( Loaded { m | zone = z }, Cmd.none )
( TimeZoneReceivedResult (Ok ( _, zone )), Unloaded d u k _ ) ->
( Unloaded d u k zone, Cmd.none )
( TimeZoneReceivedResult (Ok ( _, zone )), Loaded m ) ->
( Loaded { m | zone = zone }, Cmd.none )
( TimeZoneReceivedResult (Err _), _ ) ->
( model, Task.perform TimeZoneReceived Time.here )
( TimeReceived p, Loaded m ) ->
( Loaded { m | time = p }, Cmd.none )
@ -121,9 +137,6 @@ update msg model =
Video p v _ ->
( Loaded { m | page = Video p v Nothing }, Cmd.none )
( TimeZoneReceived z, Loaded m ) ->
( Loaded { m | zone = z }, Cmd.none )
( SizeReceived w h, Loaded m ) ->
( Loaded { m | device = Element.classifyDevice { width = w, height = h } }
, Cmd.none