{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
module Duckling.Resolve
( Context(..)
, DucklingTime(..)
, Options(..)
, Resolve(..)
, fromUTC
, toUTC
) where
import Data.Aeson (ToJSON)
import Prelude
import qualified Data.Time as Time
import qualified Data.Time.LocalTime.TimeZone.Series as Series
import Duckling.Locale
newtype DucklingTime = DucklingTime Series.ZoneSeriesTime
deriving (Eq, Show)
data Context = Context
{ referenceTime :: DucklingTime
, locale :: Locale
}
deriving (Eq, Show)
newtype Options = Options
{ withLatent :: Bool
}
deriving (Eq, Show)
class ToJSON (ResolvedValue a) => Resolve a where
type ResolvedValue a
resolve :: Context -> Options -> a -> Maybe (ResolvedValue a, Bool)
fromUTC :: Time.UTCTime -> Time.TimeZone -> Time.ZonedTime
fromUTC (Time.UTCTime day diffTime) timeZone = Time.ZonedTime localTime timeZone
where
localTime = Time.LocalTime day timeOfDay
timeOfDay = Time.timeToTimeOfDay diffTime
toUTC :: Time.LocalTime -> Time.UTCTime
toUTC (Time.LocalTime day timeOfDay) = Time.UTCTime day diffTime
where
diffTime = Time.timeOfDayToTime timeOfDay