brianvanburken/elm-list-date/3.0.1

ListDate

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.

Conversion

dateToList : Zone -> Posix -> List 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 : Zone -> List Int -> Result String 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)

JSON

decoder : Zone -> Decoder Posix

Provides a decoder that will convert a List of Int to a Date.

encoder : Zone -> Posix -> Value

Provides an encoder that will convert a Date to a List of Int's.