graphql-engine/server/src-lib/Hasura/SQL/Time.hs
Brandon Simmons ff62d5e0bf Migrate to GHC 8.10, upgrade dependencies. Closes #4517
This also seems to squash a stubborn space leak we see with
subscriptions (linking to canonical #3388 for reference).

This may also fix some of the "Unexpected exception" websockets
exceptions we are now surfacing (see e.g. #4344)

Also: dev.sh: fix hpc reporting

Initial work on this done by Vamshi.
2020-05-13 19:13:02 -04:00

33 lines
956 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.Text as T
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 :: T.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"