1 {-# OPTIONS_GHC -fno-warn-orphans #-}
2 {-# LANGUAGE NoImplicitPrelude #-}
3 {-# LANGUAGE StandaloneDeriving #-}
5 module Parsers.Types where
7 import Gargantext.Prelude
10 import Test.QuickCheck.Instances ()
12 import Text.Parsec.Pos
13 import Text.Parsec.Error (ParseError, Message(..), newErrorMessage)
14 import Data.Time.LocalTime (ZonedTime (..), TimeZone (..), TimeOfDay(..), LocalTime(..))
15 import Data.Eq (Eq(..))
16 import Data.Either (Either(..))
18 deriving instance Eq ZonedTime
20 looseTimeOfDayPrecision :: TimeOfDay -> TimeOfDay
21 looseTimeOfDayPrecision (TimeOfDay h m _) = TimeOfDay h m 0
23 looseLocalTimePrecision :: LocalTime -> LocalTime
24 looseLocalTimePrecision (LocalTime ld ltd) = LocalTime ld $ looseTimeOfDayPrecision ltd
26 looseTimeZonePrecision :: TimeZone -> TimeZone
27 looseTimeZonePrecision (TimeZone zm _ _) = TimeZone zm False "CET"
29 looseZonedTimePrecision :: ZonedTime -> ZonedTime
30 looseZonedTimePrecision (ZonedTime lt tz) = ZonedTime (looseLocalTimePrecision lt) $ looseTimeZonePrecision tz
32 loosePrecisionEitherPEZT :: Either ParseError ZonedTime -> Either ParseError ZonedTime
33 loosePrecisionEitherPEZT (Right zt) = Right $ looseZonedTimePrecision zt
34 loosePrecisionEitherPEZT pe = pe
36 instance Arbitrary Message where
38 msgContent <- arbitrary
39 oneof $ return <$> [SysUnExpect msgContent
45 instance Arbitrary SourcePos where
50 return $ newPos sn l c
52 instance Arbitrary ParseError where
56 return $ newErrorMessage msg sp