graphql-engine/server/src-lib/Hasura/SQL/Time.hs
Daniel Harvey 88ace749bc server: Fix a bunch of HLint suggestions
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4738
GitOrigin-RevId: d0c0b13ac02ca80e51ae3d582f2e6917f76ad202
2022-06-21 11:12:42 +00:00

32 lines
837 B
Haskell

module Hasura.SQL.Time
( ZonedTimeOfDay (..),
)
where
import Data.Aeson.Types qualified as Aeson
import Data.Attoparsec.Text as A
import Data.Attoparsec.Time (timeOfDay, timeZone)
import Data.Time.LocalTime qualified as Local
import Hasura.Prelude
data ZonedTimeOfDay = ZonedTimeOfDay
{ ztodTime :: Local.TimeOfDay,
ztodZone :: Local.TimeZone
}
deriving (Show, Eq)
utc :: Local.TimeZone
utc = Local.TimeZone 0 False ""
zonedTimeOfDay :: Text -> Aeson.Parser ZonedTimeOfDay
zonedTimeOfDay t =
onLeft
(A.parseOnly (p <* endOfInput) t)
(\err -> fail $ "could not parse timetz: " ++ err)
where
p = ZonedTimeOfDay <$> timeOfDay <*> (fromMaybe utc <$> timeZone)
instance Aeson.FromJSON ZonedTimeOfDay where
parseJSON (Aeson.String t) = zonedTimeOfDay t
parseJSON _ = fail "Expecting a string for timetz"