From 8dda4c37bad7eabfbc11830a7139c6020affebe0 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 10 Nov 2024 18:53:15 +0000 Subject: [PATCH] json-encode times as epoch seconds, as elm prefers --- elm.json | 2 +- frontend/src/Main.elm | 1 + lib/Point.hs | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/elm.json b/elm.json index d8f0fb8..3235b80 100644 --- a/elm.json +++ b/elm.json @@ -10,6 +10,7 @@ "elm/core": "1.0.5", "elm/html": "1.0.0", "elm/http": "2.0.0", + "elm/json": "1.1.3", "elm/svg": "1.0.1", "elm/time": "1.0.0", "elm-explorations/test": "2.2.0", @@ -20,7 +21,6 @@ "indirect": { "elm/bytes": "1.0.8", "elm/file": "1.0.5", - "elm/json": "1.1.3", "elm/parser": "1.1.0", "elm/random": "1.0.0", "elm/url": "1.0.0", diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index c74755e..a458f3b 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -6,6 +6,7 @@ import Html.Attributes as H exposing (src, style, width, height) import Html.Events exposing (onClick) import Html.Events.Extra.Pointer as Pointer import Maybe exposing (Maybe) +import Json.Decode as D import Http import Svg exposing (Svg, svg, rect, circle, g) import Svg.Attributes as S exposing diff --git a/lib/Point.hs b/lib/Point.hs index 7f8e4b8..e573b8f 100644 --- a/lib/Point.hs +++ b/lib/Point.hs @@ -24,6 +24,7 @@ import Debug.Trace (trace, traceShow) import Text.Read (readMaybe) import Text.XML import Text.XML.Cursor as Cursor +import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds) data Pos = Pos Double Double (Maybe Double) deriving (Show, Eq) @@ -52,7 +53,7 @@ instance ToJSON Point where toJSON Point {..} = object [ "pos" .= pos, - "time" .= time, + "time" .= utcTimeToPOSIXSeconds time, "cadence" .= cadence, "power" .= power, "heartRate" .= heartRate