]> Git — Sourcephile - gargantext.git/blob - src-test/Parsers/Date.hs
[CLEAN] Graph: unoptmized distances using Data.Matrix (conditional and
[gargantext.git] / src-test / Parsers / Date.hs
1 {-|
2 Module : Parsers.Date
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
12 -}
13
14 {-# LANGUAGE NoImplicitPrelude #-}
15
16 module Parsers.Date where
17
18 import Gargantext.Prelude
19
20 import Test.Hspec
21 import Test.QuickCheck
22 import Parsers.Types
23
24 import Control.Applicative ((<*>))
25 import Data.Either (Either(..))
26 import Data.Time (ZonedTime(..))
27 import Data.Text (pack, Text)
28
29 import Text.Parsec.Error (ParseError)
30 import Duckling.Time.Types (toRFC3339)
31 import Gargantext.Parsers.Date (fromRFC3339)
32
33 fromRFC3339Inv :: Either ParseError ZonedTime -> Text
34 fromRFC3339Inv (Right z) = toRFC3339 z
35 fromRFC3339Inv (Left pe) = panic . pack $ show pe
36
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
42
43 -- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x
44
45 -- \x -> let e = Right x :: Either ParseError ZonedTime
46 -- in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)