@@ -6,67 +6,27 @@ module Instances where
66import Types
77import Data.Function (on)
88import Control.Monad
9−import Test.QuickCheck (Arbitrary(..), Gen, choose, getNonNegative, elements,
9+import Test.QuickCheck (Arbitrary(..), getNonNegative, elements,
1010 listOf1, oneof, resize)
11−import Data.Time.Clock (DiffTime, UTCTime(..), picosecondsToDiffTime)
12−import Data.Fixed (Pico)
13−import Data.Time (ZonedTime(..), LocalTime(..), TimeZone(..),
14− hoursToTimeZone, Day(..), TimeOfDay(..),
15− NominalDiffTime)
11+import Data.Time.Clock (UTCTime(..))
12+import Data.Time (ZonedTime(..), TimeZone(..))
1613import Data.Version
17−import qualified Data.Text as T
18−import Data.Text (Text)
1914import Data.Aeson.Types
2015import Control.Applicative
2116import Functions
2217
23−#if !MIN_VERSION_QuickCheck(2,8,2)
24−import qualified Data.Map as Map
25−
26−instance (Ord k, Arbitrary k, Arbitrary v) => Arbitrary (Map.Map k v) where
27− arbitrary = Map.fromList <$> arbitrary
28−#endif
18+import Test.QuickCheck.Instances ()
2919
3020-- "System" types.
3121
32−instance Arbitrary Text where
33− arbitrary = T.pack <$> arbitrary
34−
35−instance Arbitrary TimeOfDay where
36− arbitrary = do
37− h <- choose (0, 23)
38− m <- choose (0, 59)
39− s <- fromRational . toRational <$> choose (0, 59 :: Double)
40− return $ TimeOfDay h m s
41−
42−instance Arbitrary LocalTime where
43− arbitrary = LocalTime <$> arbitrary <*> arbitrary
44−
45−instance Arbitrary TimeZone where
46− arbitrary = do
47− offset <- choose (0,2) :: Gen Int
48− return $ hoursToTimeZone offset
49−
50−instance Arbitrary Day where
51− arbitrary = ModifiedJulianDay `liftM` arbitrary
52−
53−instance Arbitrary DiffTime where
54− arbitrary = (picosecondsToDiffTime . (* 1000000000)) <$>
55− choose (0, 86400000)
56−
57−instance Arbitrary UTCTime where
58− arbitrary = liftM2 UTCTime arbitrary arbitrary
59−
6022instance Arbitrary DotNetTime where
6123 arbitrary = DotNetTime `liftM` arbitrary
24+ shrink = map DotNetTime . shrink . fromDotNetTime
6225
63−instance Arbitrary ZonedTime where
64− arbitrary = liftM2 ZonedTime arbitrary arbitrary
65−
66−instance Arbitrary NominalDiffTime where
67− arbitrary = realToFrac <$> (arbitrary :: Gen Pico)
68−
69−deriving instance Eq ZonedTime
26+-- | Compare timezone part only on 'timeZoneMinutes'
27+instance Eq ZonedTime where
28+ ZonedTime a (TimeZone a' _ _) == ZonedTime b (TimeZone b' _ _) =
29+ a == b && a' == b'
7030
7131-- Compare equality to within a millisecond, allowing for rounding
7232-- error (ECMA 262 requires milliseconds to rounded to zero, not