Sometimes an API returns a List of Int's and you have to deal with it. This package helps with the conversion from and to.
dateToList : Time.Zone -> Time.Posix -> List Basics.Int
Converts a date to a List of Int's. With the head being the year and the last the milliseconds.
dateToList Time.utc (Posix 1527724800000) -- [ 2018, 5, 31, 0, 0, 0, 0 ]
dateToList Time.utc (Posix 1527779760000) -- [ 2018, 5, 31, 15, 16, 0, 0 ]
dateToList Time.utc (Posix 1527779780987) -- [ 2018, 5, 31, 15, 16, 20, 987 ]
listToDate : Time.Zone -> List Basics.Int -> Result String Time.Posix
Converts a List of Int's to a Maybe Date. It expects a total of 7 integers representing year till milisceonds. If this is not the case it will fill in the rest with zero's.
listToDate Time.utc [] -- Err ..
listToDate Time.utc [ 2018 ] -- Err ..
listToDate Time.utc [ 2018, 5 ] -- Err ..
listToDate Time.utc [ 2018, 5, 31 ] -- Ok (Posix 1527724800000)
listToDate Time.utc [ 2018, 5, 31, 15 ] -- Ok (Posix 1527778800000)
listToDate Time.utc [ 2018, 5, 31, 15, 16 ] -- Ok (Posix 1527779760000)
listToDate Time.utc [ 2018, 5, 31, 15, 16, 20, 987 ] -- Ok (Posix 1527779780987)
decoder : Time.Zone -> Json.Decode.Decoder Time.Posix
Provides a decoder that will convert a List of Int to a Date.
encoder : Time.Zone -> Time.Posix -> Json.Encode.Value
Provides an encoder that will convert a Date to a List of Int's.