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 StandaloneDeriving #-}
18 module Parsers.Types where
20 import Gargantext.Prelude
22 import Test.QuickCheck
23 import Test.QuickCheck.Instances ()
25 import Text.Parsec.Pos
26 import Text.Parsec.Error (ParseError, Message(..), newErrorMessage)
27 import Data.Time.LocalTime (ZonedTime (..), TimeZone (..), TimeOfDay(..), LocalTime(..))
28 import Data.Eq (Eq(..))
29 import Data.Either (Either(..))
31 deriving instance Eq ZonedTime
33 looseTimeOfDayPrecision :: TimeOfDay -> TimeOfDay
34 looseTimeOfDayPrecision (TimeOfDay h m _) = TimeOfDay h m 0
36 looseLocalTimePrecision :: LocalTime -> LocalTime
37 looseLocalTimePrecision (LocalTime ld ltd) = LocalTime ld $ looseTimeOfDayPrecision ltd
39 looseTimeZonePrecision :: TimeZone -> TimeZone
40 looseTimeZonePrecision (TimeZone zm _ _) = TimeZone zm False "CET"
42 looseZonedTimePrecision :: ZonedTime -> ZonedTime
43 looseZonedTimePrecision (ZonedTime lt tz) = ZonedTime (looseLocalTimePrecision lt) $ looseTimeZonePrecision tz
45 loosePrecisionEitherPEZT :: Either ParseError ZonedTime -> Either ParseError ZonedTime
46 loosePrecisionEitherPEZT (Right zt) = Right $ looseZonedTimePrecision zt
47 loosePrecisionEitherPEZT pe = pe
49 instance Arbitrary Message where
51 msgContent <- arbitrary
52 oneof $ return <$> [SysUnExpect msgContent
58 instance Arbitrary SourcePos where
63 return $ newPos sn l c
65 instance Arbitrary ParseError where
69 return $ newErrorMessage msg sp