Add Timestamp data type
parent
a53fca3326
commit
dd10d43da1
2
elm.json
2
elm.json
|
@ -8,12 +8,14 @@
|
|||
"Matrix",
|
||||
"Internal.Tools.Hashdict",
|
||||
"Internal.Tools.Iddict",
|
||||
"Internal.Tools.Timestamp",
|
||||
"Internal.Tools.VersionControl"
|
||||
],
|
||||
"elm-version": "0.19.0 <= v < 0.20.0",
|
||||
"dependencies": {
|
||||
"elm/core": "1.0.0 <= v < 2.0.0",
|
||||
"elm/json": "1.0.0 <= v < 2.0.0",
|
||||
"elm/time": "1.0.0 <= v < 2.0.0",
|
||||
"miniBill/elm-fast-dict": "1.0.0 <= v < 2.0.0"
|
||||
},
|
||||
"test-dependencies": {}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
module Internal.Tools.Timestamp exposing
|
||||
( Timestamp
|
||||
, encode, decoder
|
||||
)
|
||||
|
||||
{-| The Timestamp module is a simplification of the Timetsamp as delivered by
|
||||
elm/time. This module offers ways to work with the timestamp in meaningful ways.
|
||||
|
||||
|
||||
## Timetstamp
|
||||
|
||||
@docs Timestamp
|
||||
|
||||
|
||||
## JSON coders
|
||||
|
||||
@docs encode, decoder
|
||||
|
||||
-}
|
||||
|
||||
import Json.Decode as D
|
||||
import Json.Encode as E
|
||||
import Time
|
||||
|
||||
|
||||
{-| The Timetstamp data type representing a moment in time.
|
||||
-}
|
||||
type alias Timestamp =
|
||||
Time.Posix
|
||||
|
||||
|
||||
{-| Encode a timestamp into a JSON value.
|
||||
-}
|
||||
encode : Timestamp -> E.Value
|
||||
encode =
|
||||
Time.posixToMillis >> E.int
|
||||
|
||||
|
||||
{-| Decode a timestamp from a JSON value.
|
||||
-}
|
||||
decoder : D.Decoder Timestamp
|
||||
decoder =
|
||||
D.map Time.millisToPosix D.int
|
Loading…
Reference in New Issue