Add Timestamp data type
parent
a53fca3326
commit
dd10d43da1
2
elm.json
2
elm.json
|
@ -8,12 +8,14 @@
|
||||||
"Matrix",
|
"Matrix",
|
||||||
"Internal.Tools.Hashdict",
|
"Internal.Tools.Hashdict",
|
||||||
"Internal.Tools.Iddict",
|
"Internal.Tools.Iddict",
|
||||||
|
"Internal.Tools.Timestamp",
|
||||||
"Internal.Tools.VersionControl"
|
"Internal.Tools.VersionControl"
|
||||||
],
|
],
|
||||||
"elm-version": "0.19.0 <= v < 0.20.0",
|
"elm-version": "0.19.0 <= v < 0.20.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"elm/core": "1.0.0 <= v < 2.0.0",
|
"elm/core": "1.0.0 <= v < 2.0.0",
|
||||||
"elm/json": "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"
|
"miniBill/elm-fast-dict": "1.0.0 <= v < 2.0.0"
|
||||||
},
|
},
|
||||||
"test-dependencies": {}
|
"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