@@ -10,67 +10,27 @@ module Instances where
1010import Types
1111import Data.Function (on)
1212import Control.Monad
13−import Test.QuickCheck (Arbitrary(..), Gen, choose, getNonNegative, elements,
13+import Test.QuickCheck (Arbitrary(..), getNonNegative, elements,
1414 listOf1, oneof, resize)
15−import Data.Time.Clock (DiffTime, UTCTime(..), picosecondsToDiffTime)
16−import Data.Fixed (Pico)
17−import Data.Time (ZonedTime(..), LocalTime(..), TimeZone(..),
18− hoursToTimeZone, Day(..), TimeOfDay(..),
19− NominalDiffTime)
15+import Data.Time.Clock (UTCTime(..))
16+import Data.Time (ZonedTime(..), TimeZone(..))
2017import Data.Version
21−import qualified Data.Text as T
22−import Data.Text (Text)
2318import Data.Aeson.Types
2419import Control.Applicative
2520import Functions
2621
27−#if !MIN_VERSION_QuickCheck(2,8,2)
28−import qualified Data.Map as Map
29−
30−instance (Ord k, Arbitrary k, Arbitrary v) => Arbitrary (Map.Map k v) where
31− arbitrary = Map.fromList <$> arbitrary
32−#endif
22+import Test.QuickCheck.Instances ()
3323
3424-- "System" types.
3525
36−instance Arbitrary Text where
37− arbitrary = T.pack <$> arbitrary
38−
39−instance Arbitrary TimeOfDay where
40− arbitrary = do
41− h <- choose (0, 23)
42− m <- choose (0, 59)
43− s <- fromRational . toRational <$> choose (0, 59 :: Double)
44− return $ TimeOfDay h m s
45−
46−instance Arbitrary LocalTime where
47− arbitrary = LocalTime <$> arbitrary <*> arbitrary
48−
49−instance Arbitrary TimeZone where
50− arbitrary = do
51− offset <- choose (0,2) :: Gen Int
52− return $ hoursToTimeZone offset
53−
54−instance Arbitrary Day where
55− arbitrary = ModifiedJulianDay `liftM` arbitrary
56−
57−instance Arbitrary DiffTime where
58− arbitrary = (picosecondsToDiffTime . (* 1000000000)) <$>
59− choose (0, 86400000)
60−
61−instance Arbitrary UTCTime where
62− arbitrary = liftM2 UTCTime arbitrary arbitrary
63−
6426instance Arbitrary DotNetTime where
6527 arbitrary = DotNetTime `liftM` arbitrary
28+ shrink = map DotNetTime . shrink . fromDotNetTime
6629
67−instance Arbitrary ZonedTime where
68− arbitrary = liftM2 ZonedTime arbitrary arbitrary
69−
70−instance Arbitrary NominalDiffTime where
71− arbitrary = realToFrac <$> (arbitrary :: Gen Pico)
72−
73−deriving instance Eq ZonedTime
30+-- | Compare timezone part only on 'timeZoneMinutes'
31+instance Eq ZonedTime where
32+ ZonedTime a (TimeZone a' _ _) == ZonedTime b (TimeZone b' _ _) =
33+ a == b && a' == b'
7434
7535-- Compare equality to within a millisecond, allowing for rounding
7636-- error (ECMA 262 requires milliseconds to rounded to zero, not