mirror of
https://github.com/postgres-haskell/postgres-wire.git
synced 2024-11-21 20:20:16 +03:00
pgtype timetz support (assume UTC)
This commit is contained in:
parent
5981e2cc43
commit
2c1beb4275
@ -18,6 +18,7 @@ module Database.PostgreSQL.Protocol.Codecs.Decoders
|
||||
, numeric
|
||||
, bsText
|
||||
, time
|
||||
, timetz
|
||||
, timestamp
|
||||
, timestamptz
|
||||
, uuid
|
||||
@ -169,6 +170,13 @@ bsText = getByteString
|
||||
time :: FieldDecoder TimeOfDay
|
||||
time _ = mcsToTimeOfDay <$> getInt64BE
|
||||
|
||||
{-# INLINE timetz #-}
|
||||
timetz :: FieldDecoder TimeOfDay
|
||||
timetz _ = do
|
||||
t <- getInt64BE
|
||||
skipBytes 4
|
||||
return $ mcsToTimeOfDay t
|
||||
|
||||
{-# INLINE timestamp #-}
|
||||
timestamp :: FieldDecoder LocalTime
|
||||
timestamp _ = microsToLocalTime <$> getInt64BE
|
||||
|
@ -14,6 +14,7 @@ module Database.PostgreSQL.Protocol.Codecs.Encoders
|
||||
, numeric
|
||||
, bsText
|
||||
, time
|
||||
, timetz
|
||||
, timestamp
|
||||
, timestamptz
|
||||
, uuid
|
||||
@ -48,7 +49,7 @@ bytea = putByteString
|
||||
{-# INLINE char #-}
|
||||
char :: Char -> Encode
|
||||
char c
|
||||
| ord(c) >= 128 = error "Character code must be below 128"
|
||||
| ord c >= 128 = error "Character code must be below 128"
|
||||
| otherwise = (putWord8 . fromIntegral . ord) c
|
||||
|
||||
{-# INLINE date #-}
|
||||
@ -109,6 +110,10 @@ bsText = putByteString
|
||||
time :: TimeOfDay -> Encode
|
||||
time = putInt64BE . timeOfDayToMcs
|
||||
|
||||
{-# INLINE timetz #-}
|
||||
timetz :: TimeOfDay -> Encode
|
||||
timetz t = putInt64BE (timeOfDayToMcs t) <> putInt32BE 0
|
||||
|
||||
{-# INLINE timestamp #-}
|
||||
timestamp :: LocalTime -> Encode
|
||||
timestamp = putInt64BE . localTimeToMicros
|
||||
|
@ -19,6 +19,7 @@ module Database.PostgreSQL.Protocol.Codecs.PgTypes
|
||||
, numeric
|
||||
, text
|
||||
, time
|
||||
, timetz
|
||||
, timestamp
|
||||
, timestamptz
|
||||
, uuid
|
||||
@ -92,6 +93,9 @@ text = mkOids 25 1009
|
||||
time :: Oids
|
||||
time = mkOids 1083 1183
|
||||
|
||||
timetz :: Oids
|
||||
timetz = mkOids 1266 1270
|
||||
|
||||
timestamp :: Oids
|
||||
timestamp = mkOids 1114 1115
|
||||
|
||||
|
@ -7,8 +7,10 @@ module Database.PostgreSQL.Protocol.Codecs.Time
|
||||
, microsToUTC
|
||||
, microsToLocalTime
|
||||
, mcsToTimeOfDay
|
||||
, mcsToDiffTime
|
||||
, intervalToDiffTime
|
||||
, diffTimeToInterval
|
||||
, diffTimeToMcs
|
||||
) where
|
||||
|
||||
import Data.Int (Int64, Int32, Int64)
|
||||
|
@ -111,6 +111,7 @@ testCodecsEncodeDecode = testGroup "Codecs property 'encode . decode = id'"
|
||||
, mkCodecTest "numeric" PGT.numeric PE.numeric PD.numeric
|
||||
, mkCodecTest "text" PGT.text PE.bsText PD.bsText
|
||||
, mkCodecTest "time" PGT.time PE.time PD.time
|
||||
, mkCodecTest "timetz" PGT.timetz PE.timetz PD.timetz
|
||||
, mkCodecTest "timestamp" PGT.timestamp PE.timestamp PD.timestamp
|
||||
, mkCodecTest "timestamptz" PGT.timestamptz PE.timestamptz PD.timestamptz
|
||||
, mkCodecTest "uuid" PGT.uuid PE.uuid PD.uuid
|
||||
|
Loading…
Reference in New Issue
Block a user