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@.
14 {-# LANGUAGE NoImplicitPrelude #-}
16 module Parsers.Date where
18 import Gargantext.Prelude
21 import Test.QuickCheck
24 import Control.Applicative ((<*>))
25 import Data.Either (Either(..))
26 import Data.Time (ZonedTime(..))
27 import Data.Text (pack, Text)
29 import Text.Parsec.Error (ParseError)
30 import Duckling.Time.Types (toRFC3339)
31 import Gargantext.Parsers.Date (fromRFC3339)
33 fromRFC3339Inv :: Either ParseError ZonedTime -> Text
34 fromRFC3339Inv (Right z) = toRFC3339 z
35 fromRFC3339Inv (Left pe) = panic . pack $ show pe
37 testFromRFC3339 :: IO ()
38 testFromRFC3339 = hspec $ do
39 describe "Test fromRFC3339: " $ do
40 it "is the inverse of Duckling's toRFC3339" $ property $
41 ((==) <*> (fromRFC3339 . fromRFC3339Inv)) . Right . looseZonedTimePrecision
43 -- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x
45 -- \x -> let e = Right x :: Either ParseError ZonedTime
46 -- in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)