mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 04:51:35 +03:00
88ace749bc
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4738 GitOrigin-RevId: d0c0b13ac02ca80e51ae3d582f2e6917f76ad202
32 lines
837 B
Haskell
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"
|