mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-16 09:51:59 +03:00
32 lines
911 B
Haskell
32 lines
911 B
Haskell
module Hasura.SQL.Time
|
|
( ZonedTimeOfDay(..)
|
|
) where
|
|
|
|
import Data.Attoparsec.Text as A
|
|
import Data.Attoparsec.Time (timeOfDay, timeZone)
|
|
import Hasura.Prelude
|
|
|
|
import qualified Data.Aeson.Types as Aeson
|
|
import qualified Data.Time.LocalTime as Local
|
|
|
|
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 =
|
|
case A.parseOnly (p <* endOfInput) t of
|
|
Left err -> fail $ "could not parse timetz: " ++ err
|
|
Right r -> return r
|
|
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"
|