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 {-# OPTIONS_GHC -fno-warn-orphans #-}
16 {-# LANGUAGE NoImplicitPrelude #-}
17 {-# LANGUAGE StandaloneDeriving #-}
19 module Parsers.Types where
21 import Gargantext.Prelude
23 import Test.QuickCheck
24 import Test.QuickCheck.Instances ()
26 import Text.Parsec.Pos
27 import Text.Parsec.Error (ParseError, Message(..), newErrorMessage)
28 import Data.Time.LocalTime (ZonedTime (..), TimeZone (..), TimeOfDay(..), LocalTime(..))
29 import Data.Eq (Eq(..))
30 import Data.Either (Either(..))
32 deriving instance Eq ZonedTime
34 looseTimeOfDayPrecision :: TimeOfDay -> TimeOfDay
35 looseTimeOfDayPrecision (TimeOfDay h m _) = TimeOfDay h m 0
37 looseLocalTimePrecision :: LocalTime -> LocalTime
38 looseLocalTimePrecision (LocalTime ld ltd) = LocalTime ld $ looseTimeOfDayPrecision ltd
40 looseTimeZonePrecision :: TimeZone -> TimeZone
41 looseTimeZonePrecision (TimeZone zm _ _) = TimeZone zm False "CET"
43 looseZonedTimePrecision :: ZonedTime -> ZonedTime
44 looseZonedTimePrecision (ZonedTime lt tz) = ZonedTime (looseLocalTimePrecision lt) $ looseTimeZonePrecision tz
46 loosePrecisionEitherPEZT :: Either ParseError ZonedTime -> Either ParseError ZonedTime
47 loosePrecisionEitherPEZT (Right zt) = Right $ looseZonedTimePrecision zt
48 loosePrecisionEitherPEZT pe = pe
50 instance Arbitrary Message where
52 msgContent <- arbitrary
53 oneof $ return <$> [SysUnExpect msgContent
59 instance Arbitrary SourcePos where
64 return $ newPos sn l c
66 instance Arbitrary ParseError where
70 return $ newErrorMessage msg sp