brianvanburken/elm-list-date/2.0.0

NOTE: this package is not compatible with Elm 0.19.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 : Date -> List Int

Converts a date to a List of Int's. With the head being the year and the last the milliseconds.

dateToList date -- [ 2018, 5, 31,  0,  0,  0, 0 ]
dateToList date -- [ 2018, 5, 31, 15, 16,  0, 0 ]
dateToList date -- [ 2018, 5, 31, 15, 16, 20, 1000 ]
listToDate : List Int -> Result String Date

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 [] -- Err ..
listToDate [ 2018 ] -- Err ..
listToDate [ 2018, 5 ] -- Err ..
listToDate [ 2018, 5, 31 ] -- Ok <Thu May 31 00:00:00 GMT+0000>
listToDate [ 2018, 5, 31, 15 ] -- Ok <Thu May 31 15:16:00 CMT+0000>
listToDate [ 2018, 5, 31, 15, 16 ] -- Ok <Thu May 31 15:16:00 CMT+0000>
listToDate [ 2018, 5, 31, 15, 16, 20, 987 ] -- Ok <Thu May 31 15:16:20 CMT+0000>

JSON

decoder : Decoder Date

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

encoder : Date -> Value

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