1 module Data.Gargantext.Parsers.Date where
3 import Data.Time.Clock (UTCTime, getCurrentTime)
4 import Data.Time.LocalTime.TimeZone.Series (zonedTimeToZoneSeriesTime)
5 import Data.Time.LocalTime (utc)
6 import Duckling.Resolve (fromUTC, Context(Context, referenceTime, locale)
7 , DucklingTime(DucklingTime)
9 --import Duckling.Core (makeLocale, Lang(FR,EN), Some(This), Dimension(Time))
10 import Duckling.Core (makeLocale, Lang(), Some(This), Dimension(Time))
12 import Duckling.Api (analyze)
13 import qualified Data.HashSet as HashSet
15 import Data.Text (Text)
16 -- import Duckling.Engine (parseAndResolve)
17 -- import Duckling.Rules (rulesFor)
18 -- import Duckling.Debug as DB
19 import Duckling.Types (ResolvedToken)
21 -- TODO add Paris at Duckling.Locale Region datatype
23 utcToDucklingTime :: UTCTime -> DucklingTime
24 utcToDucklingTime time = DucklingTime . zonedTimeToZoneSeriesTime $ fromUTC time utc
26 localContext :: Lang -> DucklingTime -> Context
27 localContext lang dt = Context {referenceTime = dt, locale = makeLocale lang Nothing}
29 parseDate :: Lang -> Text -> IO [ResolvedToken]
30 parseDate lang input = do
31 ctx <- localContext lang <$> utcToDucklingTime <$> getCurrentTime
32 --pure $ parseAndResolve (rulesFor (locale ctx) (HashSet.fromList [(This Time)])) input ctx
33 pure $ analyze input ctx $ HashSet.fromList [(This Time)]