Expose fromZonedTime

Summary: See #37

Reviewed By: JonCoens

Differential Revision: D5172801

fbshipit-source-id: bf63303
This commit is contained in:
Julien Odent 2017-06-02 10:52:52 -07:00 committed by Facebook Github Bot
parent b69874cd9f
commit 4a1741528c
3 changed files with 10 additions and 10 deletions

View File

@ -25,16 +25,17 @@ module Duckling.Core
-- Reference time builders
, currentReftime
, fromZonedTime
, makeReftime
) where
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.Maybe
import Data.Text (Text)
import Data.Time
import Data.Time.LocalTime.TimeZone.Series
import Prelude
import qualified Data.HashMap.Strict as HashMap
import Duckling.Api
import Duckling.Dimensions.Types
@ -56,3 +57,8 @@ currentReftime :: HashMap Text TimeZoneSeries -> Text -> IO DucklingTime
currentReftime series tz = do
utcNow <- getCurrentTime
return $ makeReftime series tz utcNow
-- | Builds a `DucklingTime` from a `ZonedTime`.
fromZonedTime :: ZonedTime -> DucklingTime
fromZonedTime (ZonedTime localTime timeZone) = DucklingTime $
ZoneSeriesTime (toUTC localTime) (TimeZoneSeries timeZone [])

View File

@ -14,15 +14,13 @@ module Duckling.Resolve
, DucklingTime(..)
, Resolve(..)
, fromUTC
, fromZonedTime
, toUTC
) where
import Data.Aeson
import Data.String
import Prelude
import qualified Data.Time as Time
import qualified Data.Time.LocalTime.TimeZone.Series as Series
import Prelude
import Duckling.Lang
@ -42,10 +40,6 @@ class ToJSON (ResolvedValue a) => Resolve a where
type ResolvedValue a
resolve :: Context -> a -> Maybe (ResolvedValue a)
fromZonedTime :: Time.ZonedTime -> DucklingTime
fromZonedTime (Time.ZonedTime localTime timeZone) = DucklingTime $
Series.ZoneSeriesTime (toUTC localTime) (Series.TimeZoneSeries timeZone [])
-- | Given a UTCTime and an TimeZone, build a ZonedTime (no conversion)
fromUTC :: Time.UTCTime -> Time.TimeZone -> Time.ZonedTime
fromUTC (Time.UTCTime day diffTime) timeZone = Time.ZonedTime localTime timeZone

View File

@ -26,11 +26,11 @@ module Duckling.Testing.Types
import Data.Aeson
import Data.Fixed (Pico)
import qualified Data.Time as Time
import Data.Text (Text)
import Prelude
import qualified Data.Time as Time
import Duckling.Lang
import Duckling.Core
import Duckling.Resolve
import Duckling.Types