Skip to content

Commit f5b37b1

Browse files
authored
Merge pull request #584 from Daniel-Diaz/master
FromJSON and ToJSON instances for CTime
2 parents 2248895 + 42b690d commit f5b37b1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Data/Aeson/Types/FromJSON.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import Data.Vector (Vector)
109109
import Data.Version (Version, parseVersion)
110110
import Data.Word (Word16, Word32, Word64, Word8)
111111
import Foreign.Storable (Storable)
112+
import Foreign.C.Types (CTime (..))
112113
import GHC.Generics
113114
import Numeric.Natural (Natural)
114115
import Text.ParserCombinators.ReadP (readP_to_S)
@@ -1351,6 +1352,9 @@ instance FromJSON Word64 where
13511352
instance FromJSONKey Word64 where
13521353
fromJSONKey = FromJSONKeyTextParser $ parseBoundedIntegralText "Word64"
13531354

1355+
instance FromJSON CTime where
1356+
parseJSON = fmap CTime . parseJSON
1357+
{-# INLINE parseJSON #-}
13541358

13551359
instance FromJSON Text where
13561360
parseJSON = withText "Text" pure

Data/Aeson/Types/ToJSON.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import Data.Vector (Vector)
9191
import Data.Version (Version, showVersion)
9292
import Data.Word (Word16, Word32, Word64, Word8)
9393
import Foreign.Storable (Storable)
94+
import Foreign.C.Types (CTime (..))
9495
import GHC.Generics
9596
import Numeric.Natural (Natural)
9697
import qualified Data.Aeson.Encoding as E
@@ -1366,7 +1367,6 @@ instance ToJSONKey Int64 where
13661367
toJSONKey = toJSONKeyTextEnc E.int64Text
13671368
{-# INLINE toJSONKey #-}
13681369

1369-
13701370
instance 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

14301436
instance ToJSON Text where
14311437
toJSON = String

0 commit comments

Comments
 (0)