agrafix / agrafix/elm-bridge

How to deal with UTCTime?

Offen
#32 20 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Elm
Sterne
107
Forks
28
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

What's the best way to deal with UTCTime? I tried deriving the Elm definition and here's what showed-up on the Elm side:

```
type alias UTCTime =
{ utctDay: Day
, utctDayTime: DiffTime
}

jsonDecUTCTime : Json.Decode.Decoder ( UTCTime )
jsonDecUTCTime =
("utctDay" := jsonDecDay) >>= \putctDay ->
("utctDayTime" := jsonDecDiffTime) >>= \putctDayTime ->
Json.Decode.succeed {utctDay = putctDay, utctDayTime = putctDayTime}

jsonEncUTCTime : UTCTime -> Value
jsonEncUTCTime val =
Json.Encode.object
[ ("utctDay", jsonEncDay val.utctDay)
, ("utctDayTime", jsonEncDiffTime val.utctDayTime)
]
```

Is this the idiomatic way of dealing with timestamps on the Elm side? (I'm new to Elm, so please pardon this newbie question). If not, then how does one specify some sort of "mapping" between an idiomatic Haskell type and its corresponding idiomatic Elm counterpart?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.