on develop help sign in
Adding explicit internal date/time types matching JSON Schema RFC

.. for serialisation purposes.

commit65605a1a3afd868a13dda75d89326573b7e83142 authorBrendan Hay <brendan.g.hay@gmail.com> dateFri 2 Oct 2015, 16:45 (11 years ago) parent0afdf3b
3 files changed+39−26
core/src/Network/Google/Prelude.hs+9 gen/src/Gen/Syntax.hs+26−24 gen/src/Gen/Types/Schema.hs+4−2
core/src/Network/Google/Prelude.hs+9
@@ -55,6 +55,15 @@ _Default = iso f Just
5555 f (Just x) = x
5656 f Nothing = mempty
5757
58+data Time = Time Text
59+ deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText, FromText)
60+
61+data Date = Date Text
62+ deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText, FromText)
63+
64+data DateTime = DateTime Text
65+ deriving (Eq, Ord, Show, Read, Generic, Data, Typeable, ToText, FromText)
66+
5867data AltJSON = AltJSON
5968 deriving (Eq, Ord, Show, Read, Generic, Data, Typeable)
6069
gen/src/Gen/Syntax.hs+26−24
@@ -386,18 +386,19 @@ internalType = \case
386386
387387externalLit :: Lit -> Type
388388externalLit = \case
389− Text -> TyCon "Text"
390− Bool -> TyCon "Bool"
391− Time -> TyCon "UTCTime"
392− Date -> TyCon "UTCTime"
393− Nat -> TyCon "Natural"
394− Float -> TyCon "Float"
395− Double -> TyCon "Double"
396− Byte -> TyCon "Word8"
397− UInt32 -> TyCon "Word32"
398− UInt64 -> TyCon "Word64"
399− Int32 -> TyCon "Int32"
400− Int64 -> TyCon "Int64"
389+ Text -> TyCon "Text"
390+ Bool -> TyCon "Bool"
391+ Time -> TyCon "UTCTime"
392+ Date -> TyCon "UTCTime"
393+ DateTime -> TyCon "UTCTime"
394+ Nat -> TyCon "Natural"
395+ Float -> TyCon "Float"
396+ Double -> TyCon "Double"
397+ Byte -> TyCon "Word8"
398+ UInt32 -> TyCon "Word32"
399+ UInt64 -> TyCon "Word64"
400+ Int32 -> TyCon "Int32"
401+ Int64 -> TyCon "Int64"
401402
402403 Alt t -> TyCon (unqual (Text.unpack t))
403404 Key -> TyCon "Key"
@@ -406,18 +407,19 @@ externalLit = \case
406407
407408internalLit :: Lit -> Type
408409internalLit = \case
409− Text -> TyCon "Text"
410− Bool -> TyCon "Bool"
411− Time -> TyCon "UTCTime"
412− Date -> TyCon "UTCTime"
413− Nat -> TyCon "Nat"
414− Float -> TyCon "Float"
415− Double -> TyCon "Double"
416− Byte -> TyCon "Word8"
417− UInt32 -> TyCon "Word32"
418− UInt64 -> TyCon "Word64"
419− Int32 -> TyCon "Int32"
420− Int64 -> TyCon "Int64"
410+ Text -> TyCon "Text"
411+ Bool -> TyCon "Bool"
412+ Time -> TyCon "Time"
413+ Date -> TyCon "Date"
414+ DateTime -> TyCon "DateTime"
415+ Nat -> TyCon "Nat"
416+ Float -> TyCon "Float"
417+ Double -> TyCon "Double"
418+ Byte -> TyCon "Word8"
419+ UInt32 -> TyCon "Word32"
420+ UInt64 -> TyCon "Word64"
421+ Int32 -> TyCon "Int32"
422+ Int64 -> TyCon "Int64"
421423
422424 Alt t -> TyCon (unqual (Text.unpack t))
423425 Key -> TyCon "Key"
gen/src/Gen/Types/Schema.hs+4−2
@@ -188,8 +188,9 @@ data Lit
188188 | Int32
189189 | Int64
190190 | Nat
191− | Date
192191 | Time
192+ | Date
193+ | DateTime
193194 -- Core types.
194195 | Body
195196 | Alt Text
@@ -213,8 +214,9 @@ instance FromJSON Lit where
213214 "uint64" -> pure UInt64
214215 "int32" -> pure Int32
215216 "int64" -> pure Int64
217+ "time" -> pure Time
216218 "date" -> pure Date
217− "date-time" -> pure Time
219+ "date-time" -> pure DateTime
218220
219221 _ -> fail $
220222 "Unable to parse Literal from: " ++ Text.unpack t