graphql-engine/server/src-lib/Hasura/SQL/Time.hs
Vamshi Surabhi ec8b2c80b5
refactor to remove warnings especially with orphan instances (#1163)
* remove phase one/two distinction and hdbquery typeclass

* move extensions to default-extensions

* switch to LazyTx which only acquires a connection if needed

* move defns from TH module into Ops module

* remove tojson orphan instance for http exception

* remove orphan instance for dmlp1

* getTopLevelNodes will not throw any exceptions
2018-12-13 12:56:15 +05:30

34 lines
1006 B
Haskell

module Hasura.SQL.Time
( ZonedTimeOfDay(..)
) where
import Data.Attoparsec.Text as A
import Data.Attoparsec.Time (timeOfDay, timeZone)
import Data.Maybe (fromMaybe)
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"