1 {-# LANGUAGE NoImplicitPrelude #-}
3 module Parsers.Date where
5 import Gargantext.Prelude
11 import Control.Applicative ((<*>))
12 import Data.Tuple (uncurry)
13 import Data.Either (Either(..))
14 import Data.Time (ZonedTime(..))
15 import Data.Text (pack, Text)
17 import Text.Parsec.Error (ParseError)
18 import Duckling.Time.Types (toRFC3339)
19 import Gargantext.Parsers.Date (fromRFC3339)
21 fromRFC3339Inv :: Either ParseError ZonedTime -> Text
22 fromRFC3339Inv (Right z) = toRFC3339 z
23 fromRFC3339Inv (Left pe) = panic . pack $ show pe
25 testFromRFC3339 :: IO ()
26 testFromRFC3339 = hspec $ do
27 describe "Test fromRFC3339: " $ do
28 it "is the inverse of Duckling's toRFC3339" $ property $
29 ((==) <*> (fromRFC3339 . fromRFC3339Inv)) . Right . looseZonedTimePrecision
31 -- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x
33 -- \x -> let e = Right x :: Either ParseError ZonedTime
34 -- in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)