on master help sign in
Merge pull request #421 from phadej/time-keys
f81a260Adam Bergmark
Data/Aeson/Encoding.hs+13
@@ -6,12 +6,15 @@ module Data.Aeson.Encoding
6 , unsafeToEncoding
6 , unsafeToEncoding
7 , Series
7 , Series
8 , pairs
8 , pairs
9+ , pair
9 -- * Predicates
10 -- * Predicates
10 , nullEncoding
11 , nullEncoding
11 -- * Encoding constructors
12 -- * Encoding constructors
12 , emptyArray_
13 , emptyArray_
13 , emptyObject_
14 , emptyObject_
14 , text
15 , text
16+ , lazyText
17+ , string
15 , list
18 , list
16 , dict
19 , dict
17 , null_
20 , null_
@@ -25,6 +28,16 @@ module Data.Aeson.Encoding
25 , int8Text, int16Text, int32Text, int64Text, intText
28 , int8Text, int16Text, int32Text, int64Text, intText
26 , word8Text, word16Text, word32Text, word64Text, wordText
29 , word8Text, word16Text, word32Text, word64Text, wordText
27 , integerText, floatText, doubleText, scientificText
30 , integerText, floatText, doubleText, scientificText
31+
32+ -- ** Time
33+ , day
34+ , localTime
35+ , utcTime
36+ , timeOfDay
37+ , zonedTime
38+
39+ -- ** value
40+ , value
28 ) where
41 ) where
29
42
30import Data.Aeson.Encoding.Internal
43import Data.Aeson.Encoding.Internal
Data/Aeson/Encoding/Internal.hs+54−1
@@ -1,7 +1,7 @@
1{-# LANGUAGE DeriveDataTypeable #-}
1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3−{-# LANGUAGE RankNTypes #-}
4{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE OverloadedStrings #-}
4+{-# LANGUAGE RankNTypes #-}
5module Data.Aeson.Encoding.Internal
5module Data.Aeson.Encoding.Internal
6 (
6 (
7 -- * Encoding
7 -- * Encoding
@@ -9,6 +9,7 @@ module Data.Aeson.Encoding.Internal
9 , unsafeToEncoding
9 , unsafeToEncoding
10 , Series (..) -- TODO: don't export constructor
10 , Series (..) -- TODO: don't export constructor
11 , pairs
11 , pairs
12+ , pair
12 -- * Predicates
13 -- * Predicates
13 , nullEncoding
14 , nullEncoding
14 -- * Encoding constructors
15 -- * Encoding constructors
@@ -19,6 +20,8 @@ module Data.Aeson.Encoding.Internal
19 , null_
20 , null_
20 , bool
21 , bool
21 , text
22 , text
23+ , lazyText
24+ , string
22 , list
25 , list
23 , dict
26 , dict
24 , tuple
27 , tuple
@@ -31,6 +34,14 @@ module Data.Aeson.Encoding.Internal
31 , int8Text, int16Text, int32Text, int64Text, intText
34 , int8Text, int16Text, int32Text, int64Text, intText
32 , word8Text, word16Text, word32Text, word64Text, wordText
35 , word8Text, word16Text, word32Text, word64Text, wordText
33 , integerText, floatText, doubleText, scientificText
36 , integerText, floatText, doubleText, scientificText
37+ -- ** Time
38+ , day
39+ , localTime
40+ , utcTime
41+ , timeOfDay
42+ , zonedTime
43+ -- ** value
44+ , value
34 -- ** JSON tokens
45 -- ** JSON tokens
35 , comma, colon, openBracket, closeBracket, openCurly, closeCurly
46 , comma, colon, openBracket, closeBracket, openCurly, closeCurly
36 ) where
47 ) where
@@ -44,12 +55,17 @@ import Data.Int
44import Data.Scientific (Scientific)
55import Data.Scientific (Scientific)
45import Data.Semigroup (Semigroup ((<>)))
56import Data.Semigroup (Semigroup ((<>)))
46import Data.Text (Text)
57import Data.Text (Text)
58+import Data.Time (Day, LocalTime, TimeOfDay, UTCTime,
59+ ZonedTime)
47import Data.Typeable (Typeable)
60import Data.Typeable (Typeable)
48import Data.Word
61import Data.Word
49
62
63+import Data.Aeson.Types.Internal (Value)
64+
50import qualified Data.Aeson.Encode.Builder as EB
65import qualified Data.Aeson.Encode.Builder as EB
51import qualified Data.ByteString.Builder as B
66import qualified Data.ByteString.Builder as B
52import qualified Data.ByteString.Lazy as BSL
67import qualified Data.ByteString.Lazy as BSL
68+import qualified Data.Text.Lazy as LT
53
69
54-- | An encoding of a JSON value.
70-- | An encoding of a JSON value.
55newtype Encoding = Encoding {
71newtype Encoding = Encoding {
@@ -89,6 +105,9 @@ data Series = Empty
89 | Value Encoding
105 | Value Encoding
90 deriving (Typeable)
106 deriving (Typeable)
91
107
108+pair :: Text -> Encoding -> Series
109+pair name val = Value $ text name <> colon <> val
110+
92instance Semigroup Series where
111instance Semigroup Series where
93 Empty <> a = a
112 Empty <> a = a
94 Value a <> b =
113 Value a <> b =
@@ -174,6 +193,14 @@ tuple b = Encoding (char7 '[' <> fromEncoding b <> char7 ']')
174text :: Text -> Encoding
193text :: Text -> Encoding
175text = Encoding . EB.text
194text = Encoding . EB.text
176
195
196+lazyText :: LT.Text -> Encoding
197+lazyText t = Encoding $
198+ B.char7 '"' <>
199+ LT.foldrChunks (\x xs -> EB.unquoted x <> xs) (B.char7 '"') t
200+
201+string :: String -> Encoding
202+string = Encoding . EB.string
203+
177-------------------------------------------------------------------------------
204-------------------------------------------------------------------------------
178-- chars
205-- chars
179-------------------------------------------------------------------------------
206-------------------------------------------------------------------------------
@@ -284,3 +311,29 @@ doubleText = Encoding . EB.quote . B.doubleDec
284
311
285scientificText :: Scientific -> Encoding
312scientificText :: Scientific -> Encoding
286scientificText = Encoding . EB.quote . EB.scientific
313scientificText = Encoding . EB.quote . EB.scientific
314+
315+-------------------------------------------------------------------------------
316+-- time
317+-------------------------------------------------------------------------------
318+
319+day :: Day -> Encoding
320+day = Encoding . EB.quote . EB.day
321+
322+localTime :: LocalTime -> Encoding
323+localTime = Encoding . EB.quote . EB.localTime
324+
325+utcTime :: UTCTime -> Encoding
326+utcTime = Encoding . EB.quote . EB.utcTime
327+
328+timeOfDay :: TimeOfDay -> Encoding
329+timeOfDay = Encoding . EB.quote . EB.timeOfDay
330+
331+zonedTime :: ZonedTime -> Encoding
332+zonedTime = Encoding . EB.quote . EB.zonedTime
333+
334+-------------------------------------------------------------------------------
335+-- Value
336+-------------------------------------------------------------------------------
337+
338+value :: Value -> Encoding
339+value = Encoding . EB.encodeToBuilder
Data/Aeson/Types/FromJSON.hs+20
@@ -1382,18 +1382,38 @@ instance FromJSON DotNetTime where
1382instance FromJSON Day where
1382instance FromJSON Day where
1383 parseJSON = withText "Day" (Time.run Time.day)
1383 parseJSON = withText "Day" (Time.run Time.day)
1384
1384
1385+instance FromJSONKey Day where
1386+ fromJSONKey = FromJSONKeyTextParser (Time.run Time.day)
1387+
1388+
1385instance FromJSON TimeOfDay where
1389instance FromJSON TimeOfDay where
1386 parseJSON = withText "TimeOfDay" (Time.run Time.timeOfDay)
1390 parseJSON = withText "TimeOfDay" (Time.run Time.timeOfDay)
1387
1391
1392+instance FromJSONKey TimeOfDay where
1393+ fromJSONKey = FromJSONKeyTextParser (Time.run Time.timeOfDay)
1394+
1395+
1388instance FromJSON LocalTime where
1396instance FromJSON LocalTime where
1389 parseJSON = withText "LocalTime" (Time.run Time.localTime)
1397 parseJSON = withText "LocalTime" (Time.run Time.localTime)
1390
1398
1399+instance FromJSONKey LocalTime where
1400+ fromJSONKey = FromJSONKeyTextParser (Time.run Time.localTime)
1401+
1402+
1391instance FromJSON ZonedTime where
1403instance FromJSON ZonedTime where
1392 parseJSON = withText "ZonedTime" (Time.run Time.zonedTime)
1404 parseJSON = withText "ZonedTime" (Time.run Time.zonedTime)
1393
1405
1406+instance FromJSONKey ZonedTime where
1407+ fromJSONKey = FromJSONKeyTextParser (Time.run Time.zonedTime)
1408+
1409+
1394instance FromJSON UTCTime where
1410instance FromJSON UTCTime where
1395 parseJSON = withText "UTCTime" (Time.run Time.utcTime)
1411 parseJSON = withText "UTCTime" (Time.run Time.utcTime)
1396
1412
1413+instance FromJSONKey UTCTime where
1414+ fromJSONKey = FromJSONKeyTextParser (Time.run Time.utcTime)
1415+
1416+
1397-- | /WARNING:/ Only parse lengths of time from trusted input
1417-- | /WARNING:/ Only parse lengths of time from trusted input
1398-- since an attacker could easily fill up the memory of the target
1418-- since an attacker could easily fill up the memory of the target
1399-- system by specifying a scientific number with a big exponent like
1419-- system by specifying a scientific number with a big exponent like
Data/Aeson/Types/ToJSON.hs+43−54
@@ -61,7 +61,7 @@ import Data.Aeson.Functions (mapHashKeyVal, mapKeyVal)
61import Data.Aeson.Types.Generic
61import Data.Aeson.Types.Generic
62import Data.Aeson.Types.Internal
62import Data.Aeson.Types.Internal
63
63
64−import qualified Data.Aeson.Encode.Builder as EB
64+-- We need internal here for generic deriving
65import qualified Data.Aeson.Encoding.Internal as E
65import qualified Data.Aeson.Encoding.Internal as E
66
66
67import Control.Applicative (Const (..))
67import Control.Applicative (Const (..))
@@ -92,7 +92,7 @@ import Foreign.Storable (Storable)
92import GHC.Generics
92import GHC.Generics
93import Numeric.Natural (Natural)
93import Numeric.Natural (Natural)
94
94
95−import qualified Data.ByteString.Builder as B
95+import qualified Data.ByteString.Builder as B (toLazyByteString)
96import qualified Data.ByteString.Lazy as L
96import qualified Data.ByteString.Lazy as L
97import qualified Data.DList as DList
97import qualified Data.DList as DList
98import qualified Data.HashMap.Strict as H
98import qualified Data.HashMap.Strict as H
@@ -115,9 +115,6 @@ import qualified Data.Vector.Primitive as VP
115import qualified Data.Vector.Storable as VS
115import qualified Data.Vector.Storable as VS
116import qualified Data.Vector.Unboxed as VU
116import qualified Data.Vector.Unboxed as VU
117
117
118−builder :: ToJSON a => a -> B.Builder
119−builder = fromEncoding . toEncoding
120−
121toJSONPair :: (a -> Value) -> (b -> Value) -> (a, b) -> Value
118toJSONPair :: (a -> Value) -> (b -> Value) -> (a, b) -> Value
122toJSONPair keySerialiser valSerializer (a, b) = Array $ V.create $ do
119toJSONPair keySerialiser valSerializer (a, b) = Array $ V.create $ do
123 mv <- VM.unsafeNew 2
120 mv <- VM.unsafeNew 2
@@ -278,7 +275,7 @@ class ToJSON a where
278 -- @
275 -- @
279
276
280 toEncoding :: a -> Encoding
277 toEncoding :: a -> Encoding
281− toEncoding = E.Encoding . EB.encodeToBuilder . toJSON
278+ toEncoding = E.value . toJSON
282 {-# INLINE toEncoding #-}
279 {-# INLINE toEncoding #-}
283
280
284 toJSONList :: [a] -> Value
281 toJSONList :: [a] -> Value
@@ -299,7 +296,7 @@ class KeyValue kv where
299 infixr 8 .=
296 infixr 8 .=
300
297
301instance KeyValue Series where
298instance KeyValue Series where
302− name .= value = E.Value $ E.text name <> E.colon <> toEncoding value
299+ name .= value = E.pair name (toEncoding value)
303 {-# INLINE (.=) #-}
300 {-# INLINE (.=) #-}
304
301
305instance KeyValue Pair where
302instance KeyValue Pair where
@@ -1192,7 +1189,7 @@ instance ToJSON1 Maybe where
1192 {-# INLINE liftToJSON #-}
1189 {-# INLINE liftToJSON #-}
1193
1190
1194 liftToEncoding t _ (Just a) = t a
1191 liftToEncoding t _ (Just a) = t a
1195− liftToEncoding _ _ Nothing = Encoding EB.null_
1192+ liftToEncoding _ _ Nothing = E.null_
1196 {-# INLINE liftToEncoding #-}
1193 {-# INLINE liftToEncoding #-}
1197
1194
1198instance (ToJSON a) => ToJSON (Maybe a) where
1195instance (ToJSON a) => ToJSON (Maybe a) where
@@ -1208,15 +1205,9 @@ instance ToJSON2 Either where
1208 liftToJSON2 _toA _ toB _ (Right b) = Object $ H.singleton right (toB b)
1205 liftToJSON2 _toA _ toB _ (Right b) = Object $ H.singleton right (toB b)
1209 {-# INLINE liftToJSON2 #-}
1206 {-# INLINE liftToJSON2 #-}
1210
1207
1211− liftToEncoding2 toA _ _toB _ (Left a) =
1208+ liftToEncoding2 toA _ _toB _ (Left a) = E.pairs $ E.pair "Left" $ toA a
1212− Encoding (B.shortByteString "{\"Left\":")
1213− <> toA a
1214− <> Encoding (B.char7 '}')
1215
1209
1216− liftToEncoding2 _toA _ toB _ (Right b) =
1210+ liftToEncoding2 _toA _ toB _ (Right b) = E.pairs $ E.pair "Right" $ toB b
1217− Encoding (B.shortByteString "{\"Right\":")
1218− <> toB b
1219− <> Encoding (B.char7 '}')
1220 {-# INLINE liftToEncoding2 #-}
1211 {-# INLINE liftToEncoding2 #-}
1221
1212
1222instance (ToJSON a) => ToJSON1 (Either a) where
1213instance (ToJSON a) => ToJSON1 (Either a) where
@@ -1277,10 +1268,10 @@ instance ToJSON Char where
1277 toJSONList = String . T.pack
1268 toJSONList = String . T.pack
1278 {-# INLINE toJSONList #-}
1269 {-# INLINE toJSONList #-}
1279
1270
1280− toEncoding = Encoding . EB.string . (:[])
1271+ toEncoding = E.string . (:[])
1281 {-# INLINE toEncoding #-}
1272 {-# INLINE toEncoding #-}
1282
1273
1283− toEncodingList = Encoding . EB.string
1274+ toEncodingList = E.string
1284 {-# INLINE toEncodingList #-}
1275 {-# INLINE toEncodingList #-}
1285
1276
1286
1277
@@ -1501,9 +1492,7 @@ instance ToJSON LT.Text where
1501 toJSON = String . LT.toStrict
1492 toJSON = String . LT.toStrict
1502 {-# INLINE toJSON #-}
1493 {-# INLINE toJSON #-}
1503
1494
1504− toEncoding t = Encoding $
1495+ toEncoding = E.lazyText
1505− B.char7 '"' <>
1506− LT.foldrChunks (\x xs -> EB.unquoted x <> xs) (B.char7 '"') t
1507 {-# INLINE toEncoding #-}
1496 {-# INLINE toEncoding #-}
1508
1497
1509instance ToJSON Version where
1498instance ToJSON Version where
@@ -1513,7 +1502,6 @@ instance ToJSON Version where
1513 toEncoding = toEncoding . showVersion
1502 toEncoding = toEncoding . showVersion
1514 {-# INLINE toEncoding #-}
1503 {-# INLINE toEncoding #-}
1515
1504
1516−
1517-------------------------------------------------------------------------------
1505-------------------------------------------------------------------------------
1518-- semigroups NonEmpty
1506-- semigroups NonEmpty
1519-------------------------------------------------------------------------------
1507-------------------------------------------------------------------------------
@@ -1686,13 +1674,7 @@ instance ToJSON1 Vector where
1686 liftToJSON t _ = Array . V.map t
1674 liftToJSON t _ = Array . V.map t
1687 {-# INLINE liftToJSON #-}
1675 {-# INLINE liftToJSON #-}
1688
1676
1689− liftToEncoding t _ xs
1677+ liftToEncoding t _ = listEncoding t . V.toList
1690− | V.null xs = emptyArray_
1691− | otherwise = Encoding $
1692− B.char7 '[' <> fromEncoding (t (V.unsafeHead xs)) <>
1693− V.foldr go (B.char7 ']') (V.unsafeTail xs)
1694− where
1695− go v b = B.char7 ',' <> fromEncoding (t v) <> b
1696 {-# INLINE liftToEncoding #-}
1678 {-# INLINE liftToEncoding #-}
1697
1679
1698instance (ToJSON a) => ToJSON (Vector a) where
1680instance (ToJSON a) => ToJSON (Vector a) where
@@ -1703,12 +1685,7 @@ instance (ToJSON a) => ToJSON (Vector a) where
1703 {-# INLINE toEncoding #-}
1685 {-# INLINE toEncoding #-}
1704
1686
1705encodeVector :: (ToJSON a, VG.Vector v a) => v a -> Encoding
1687encodeVector :: (ToJSON a, VG.Vector v a) => v a -> Encoding
1706−encodeVector xs
1688+encodeVector = listEncoding toEncoding . VG.toList
1707− | VG.null xs = emptyArray_
1708− | otherwise = Encoding $
1709− B.char7 '[' <> builder (VG.unsafeHead xs) <>
1710− VG.foldr go (B.char7 ']') (VG.unsafeTail xs)
1711− where go v b = B.char7 ',' <> builder v <> b
1712{-# INLINE encodeVector #-}
1689{-# INLINE encodeVector #-}
1713
1690
1714vectorToJSON :: (VG.Vector v a, ToJSON a) => v a -> Value
1691vectorToJSON :: (VG.Vector v a, ToJSON a) => v a -> Value
@@ -1787,7 +1764,7 @@ instance ToJSON Value where
1787 toJSON a = a
1764 toJSON a = a
1788 {-# INLINE toJSON #-}
1765 {-# INLINE toJSON #-}
1789
1766
1790− toEncoding = Encoding . EB.encodeToBuilder
1767+ toEncoding = E.value
1791 {-# INLINE toEncoding #-}
1768 {-# INLINE toEncoding #-}
1792
1769
1793instance ToJSON DotNetTime where
1770instance ToJSON DotNetTime where
@@ -1799,55 +1776,67 @@ dotNetTime :: DotNetTime -> String
1799dotNetTime (DotNetTime t) = secs ++ formatMillis t ++ ")/"
1776dotNetTime (DotNetTime t) = secs ++ formatMillis t ++ ")/"
1800 where secs = formatTime defaultTimeLocale "/Date(%s" t
1777 where secs = formatTime defaultTimeLocale "/Date(%s" t
1801
1778
1779+formatMillis :: (FormatTime t) => t -> String
1780+formatMillis = take 3 . formatTime defaultTimeLocale "%q"
1781+
1802-------------------------------------------------------------------------------
1782-------------------------------------------------------------------------------
1803-- time
1783-- time
1804-------------------------------------------------------------------------------
1784-------------------------------------------------------------------------------
1805
1785
1806instance ToJSON Day where
1786instance ToJSON Day where
1807− toJSON = stringEncoding
1787+ toJSON = stringEncoding . E.day
1808− toEncoding z = Encoding (EB.quote $ EB.day z)
1788+ toEncoding = E.day
1789+
1790+instance ToJSONKey Day where
1791+ toJSONKey = toJSONKeyTextEnc E.day
1809
1792
1810
1793
1811instance ToJSON TimeOfDay where
1794instance ToJSON TimeOfDay where
1812− toJSON = stringEncoding
1795+ toJSON = stringEncoding . E.timeOfDay
1813− toEncoding z = Encoding (EB.quote $ EB.timeOfDay z)
1796+ toEncoding = E.timeOfDay
1797+
1798+instance ToJSONKey TimeOfDay where
1799+ toJSONKey = toJSONKeyTextEnc E.timeOfDay
1814
1800
1815
1801
1816instance ToJSON LocalTime where
1802instance ToJSON LocalTime where
1817− toJSON = stringEncoding
1803+ toJSON = stringEncoding . E.localTime
1818− toEncoding z = Encoding (EB.quote $ EB.localTime z)
1804+ toEncoding = E.localTime
1805+
1806+instance ToJSONKey LocalTime where
1807+ toJSONKey = toJSONKeyTextEnc E.localTime
1808+
1819
1809
1820instance ToJSON ZonedTime where
1810instance ToJSON ZonedTime where
1821− toJSON = stringEncoding
1811+ toJSON = stringEncoding . E.zonedTime
1812+ toEncoding = E.zonedTime
1822
1813
1823− toEncoding z = Encoding (EB.quote $ EB.zonedTime z)
1814+instance ToJSONKey ZonedTime where
1815+ toJSONKey = toJSONKeyTextEnc E.zonedTime
1824
1816
1825−formatMillis :: (FormatTime t) => t -> String
1826−formatMillis = take 3 . formatTime defaultTimeLocale "%q"
1827
1817
1828instance ToJSON UTCTime where
1818instance ToJSON UTCTime where
1829− toJSON = stringEncoding
1819+ toJSON = stringEncoding . E.utcTime
1820+ toEncoding = E.utcTime
1830
1821
1831− toEncoding t = Encoding (EB.quote $ EB.utcTime t)
1822+instance ToJSONKey UTCTime where
1823+ toJSONKey = toJSONKeyTextEnc E.utcTime
1832
1824
1833-- | Encode something t a JSON string.
1825-- | Encode something t a JSON string.
1834−--
1835−-- TODO: remove me, this is a hack
1836−stringEncoding :: (ToJSON a) => a -> Value
1826+stringEncoding :: Encoding -> Value
1837stringEncoding = String
1827stringEncoding = String
1838 . T.dropAround (== '"')
1828 . T.dropAround (== '"')
1839 . T.decodeLatin1
1829 . T.decodeLatin1
1840 . L.toStrict
1830 . L.toStrict
1841 . B.toLazyByteString
1831 . B.toLazyByteString
1842 . fromEncoding
1832 . fromEncoding
1843− . toEncoding
1844{-# INLINE stringEncoding #-}
1833{-# INLINE stringEncoding #-}
1845
1834
1846instance ToJSON NominalDiffTime where
1835instance ToJSON NominalDiffTime where
1847 toJSON = Number . realToFrac
1836 toJSON = Number . realToFrac
1848 {-# INLINE toJSON #-}
1837 {-# INLINE toJSON #-}
1849
1838
1850− toEncoding = Encoding . EB.scientific . realToFrac
1839+ toEncoding = E.scientific . realToFrac
1851 {-# INLINE toEncoding #-}
1840 {-# INLINE toEncoding #-}
1852
1841
1853-------------------------------------------------------------------------------
1842-------------------------------------------------------------------------------
@@ -1906,7 +1895,7 @@ instance ToJSON (Proxy a) where
1906 toJSON _ = Null
1895 toJSON _ = Null
1907 {-# INLINE toJSON #-}
1896 {-# INLINE toJSON #-}
1908
1897
1909− toEncoding _ = Encoding EB.null_
1898+ toEncoding _ = E.null_
1910 {-# INLINE toEncoding #-}
1899 {-# INLINE toEncoding #-}
1911
1900
1912
1901
aeson.cabal+3
@@ -174,6 +174,9 @@ test-suite tests
174 if !impl(ghc >= 7.10)
174 if !impl(ghc >= 7.10)
175 build-depends: nats >=1 && <1.2
175 build-depends: nats >=1 && <1.2
176
176
177+ if impl(ghc >= 7.8)
178+ build-depends: hashable-time >= 0.2 && <0.3
179+
177source-repository head
180source-repository head
178 type: git
181 type: git
179 location: git://github.com/bos/aeson.git
182 location: git://github.com/bos/aeson.git
tests/Instances.hs+3
@@ -28,6 +28,9 @@ import qualified Data.DList as DList
28
28
29import Data.Orphans ()
29import Data.Orphans ()
30import Test.QuickCheck.Instances ()
30import Test.QuickCheck.Instances ()
31+#if MIN_VERSION_base(4,7,0)
32+import Data.Hashable.Time ()
33+#endif
31
34
32#if !MIN_VERSION_base(4,8,0) && !MIN_VERSION_QuickCheck(2,8,3)
35#if !MIN_VERSION_base(4,8,0) && !MIN_VERSION_QuickCheck(2,8,3)
33import Numeric.Natural
36import Numeric.Natural
tests/Properties.hs+7−1
@@ -1,4 +1,4 @@
1−{-# LANGUAGE OverloadedStrings, RecordWildCards, ScopedTypeVariables #-}
1+{-# LANGUAGE CPP, OverloadedStrings, ScopedTypeVariables #-}
2
2
3module Properties where
3module Properties where
4
4
@@ -186,6 +186,12 @@ tests = testGroup "properties" [
186 , testProperty "Natural" $ roundTripKey (undefined :: Natural)
186 , testProperty "Natural" $ roundTripKey (undefined :: Natural)
187 , testProperty "Float" $ roundTripKey (undefined :: Float)
187 , testProperty "Float" $ roundTripKey (undefined :: Float)
188 , testProperty "Double" $ roundTripKey (undefined :: Double)
188 , testProperty "Double" $ roundTripKey (undefined :: Double)
189+#if MIN_VERSION_base(4,7,0)
190+ , testProperty "Day" $ roundTripKey (undefined :: Day)
191+ , testProperty "LocalTime" $ roundTripKey (undefined :: LocalTime)
192+ , testProperty "TimeOfDay" $ roundTripKey (undefined :: TimeOfDay)
193+ , testProperty "UTCTime" $ roundTripKey (undefined :: UTCTime)
194+#endif
189 ]
195 ]
190 , testGroup "toFromJSON" [
196 , testGroup "toFromJSON" [
191 testProperty "Integer" (toFromJSON :: Integer -> Property)
197 testProperty "Integer" (toFromJSON :: Integer -> Property)