]> Git — Sourcephile - gargantext.git/blob - src/Data/Gargantext/Parsers/Date.hs
[FIX] hpack-convert for automatic gargantext.cabal updates (thx yann).
[gargantext.git] / src / Data / Gargantext / Parsers / Date.hs
1 module Data.Gargantext.Parsers.Date where
2
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)
8 )
9 --import Duckling.Core (makeLocale, Lang(FR,EN), Some(This), Dimension(Time))
10 import Duckling.Core (makeLocale, Lang(), Some(This), Dimension(Time))
11
12 import Duckling.Api (analyze)
13 import qualified Data.HashSet as HashSet
14
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)
20
21 -- TODO add Paris at Duckling.Locale Region datatype
22
23 utcToDucklingTime :: UTCTime -> DucklingTime
24 utcToDucklingTime time = DucklingTime . zonedTimeToZoneSeriesTime $ fromUTC time utc
25
26 localContext :: Lang -> DucklingTime -> Context
27 localContext lang dt = Context {referenceTime = dt, locale = makeLocale lang Nothing}
28
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)]