Date.hs 1.43 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
{-|
Module      : Parsers.Date
Description : 
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

Here is a longer description of this module, containing some
commentary with @some markup@.
-}

14 15 16 17 18 19 20

module Parsers.Date where


import Test.Hspec
import Test.QuickCheck

Mael NICOLAS's avatar
Mael NICOLAS committed
21
import Control.Applicative ((<*>))
22 23 24 25 26 27
import Data.Either (Either(..))
import Data.Time (ZonedTime(..))
import Data.Text (pack, Text)

import Text.Parsec.Error (ParseError)
import Duckling.Time.Types (toRFC3339)
28 29 30

-----------------------------------------------------------
import Gargantext.Prelude
Przemyslaw Kaminski's avatar
Przemyslaw Kaminski committed
31
import Gargantext.Core.Text.Corpus.Parsers.Date.Parsec (fromRFC3339)
32 33
import Parsers.Types
-----------------------------------------------------------
34 35 36

fromRFC3339Inv ::  Either ParseError ZonedTime -> Text
fromRFC3339Inv (Right z) = toRFC3339 z
Mael NICOLAS's avatar
Mael NICOLAS committed
37
fromRFC3339Inv (Left pe) = panic . pack $ show pe
38

39 40
testFromRFC3339 :: Spec
testFromRFC3339 = do
41 42
  describe "Test fromRFC3339: " $ do
    it "is the inverse of Duckling's toRFC3339" $ property $
Mael NICOLAS's avatar
Mael NICOLAS committed
43 44 45 46 47 48
      ((==) <*> (fromRFC3339 . fromRFC3339Inv)) . Right . looseZonedTimePrecision

      -- \x -> uncurry (==) $ (,) <*> (fromRFC3339 . fromRFC3339Inv) $ Right $ looseZonedTimePrecision x

      -- \x -> let e = Right x :: Either ParseError ZonedTime
      --       in fmap looseZonedTimePrecision e == (fromRFC3339 . fromRFC3339Inv ) (fmap looseZonedTimePrecision e)