4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
15 module Parsers.Date where
19 import Test.QuickCheck
21 import Control.Applicative ((<*>))
22 import Data.Either (Either(..))
23 import Data.Time (ZonedTime(..))
24 import Data.Text (pack, Text)
26 import Text.Parsec.Error (ParseError)
27 import Duckling.Time.Types (toRFC3339)
29 -----------------------------------------------------------
30 import Gargantext.Prelude
31 import Gargantext.Core.Text.Corpus.Parsers.Date.Parsec (fromRFC3339)
33 -----------------------------------------------------------
35 fromRFC3339Inv :: Either ParseError ZonedTime -> Text
36 fromRFC3339Inv (Right z) = toRFC3339 z
37 fromRFC3339Inv (Left pe) = panic . pack $ show pe
39 testFromRFC3339 :: IO ()
40 testFromRFC3339 = hspec $ do
41 describe "Test fromRFC3339: " $ do
42 it "is the inverse of Duckling's toRFC3339" $ property $
43 ((==) <*> (fromRFC3339 . fromRFC3339Inv)) . Right . looseZonedTimePrecision
45 -- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x
47 -- \x -> let e = Right x :: Either ParseError ZonedTime
48 -- in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)