on master help sign in
Merge pull request #584 from Daniel-Diaz/master

FromJSON and ToJSON instances for CTime

commitf5b37b13e40db2b6e3b26356fe3fc8a9542de51f authorAdam Bergmark <adam@bergmark.nl> dateMon 4 Sep 2017, 20:12 (9 years ago) parent224889542b690d
2 files changed+11−1
Data/Aeson/Types/FromJSON.hs+4 Data/Aeson/Types/ToJSON.hs+7−1
Data/Aeson/Types/FromJSON.hs+4
@@ -109,6 +109,7 @@ import Data.Vector (Vector)
109109import Data.Version (Version, parseVersion)
110110import Data.Word (Word16, Word32, Word64, Word8)
111111import Foreign.Storable (Storable)
112+import Foreign.C.Types (CTime (..))
112113import GHC.Generics
113114import Numeric.Natural (Natural)
114115import Text.ParserCombinators.ReadP (readP_to_S)
@@ -1351,6 +1352,9 @@ instance FromJSON Word64 where
13511352instance FromJSONKey Word64 where
13521353 fromJSONKey = FromJSONKeyTextParser $ parseBoundedIntegralText "Word64"
13531354
1355+instance FromJSON CTime where
1356+ parseJSON = fmap CTime . parseJSON
1357+ {-# INLINE parseJSON #-}
13541358
13551359instance FromJSON Text where
13561360 parseJSON = withText "Text" pure
Data/Aeson/Types/ToJSON.hs+7−1
@@ -91,6 +91,7 @@ import Data.Vector (Vector)
9191import Data.Version (Version, showVersion)
9292import Data.Word (Word16, Word32, Word64, Word8)
9393import Foreign.Storable (Storable)
94+import Foreign.C.Types (CTime (..))
9495import GHC.Generics
9596import Numeric.Natural (Natural)
9697import qualified Data.Aeson.Encoding as E
@@ -1366,7 +1367,6 @@ instance ToJSONKey Int64 where
13661367 toJSONKey = toJSONKeyTextEnc E.int64Text
13671368 {-# INLINE toJSONKey #-}
13681369
1369−
13701370instance ToJSON Word where
13711371 toJSON = Number . fromIntegral
13721372 {-# INLINE toJSON #-}
@@ -1426,6 +1426,12 @@ instance ToJSONKey Word64 where
14261426 toJSONKey = toJSONKeyTextEnc E.word64Text
14271427 {-# INLINE toJSONKey #-}
14281428
1429+instance ToJSON CTime where
1430+ toJSON (CTime i) = toJSON i
1431+ {-# INLINE toJSON #-}
1432+
1433+ toEncoding (CTime i) = toEncoding i
1434+ {-# INLINE toEncoding #-}
14291435
14301436instance ToJSON Text where
14311437 toJSON = String