File tree Expand file tree Collapse file tree 5 files changed +21
-1
lines changed
src/Database/PostgreSQL/Protocol/Codecs Expand file tree Collapse file tree 5 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ module Database.PostgreSQL.Protocol.Codecs.Decoders
1818 , numeric
1919 , bsText
2020 , time
21+ , timetz
2122 , timestamp
2223 , timestamptz
2324 , uuid
@@ -169,6 +170,13 @@ bsText = getByteString
169170time :: FieldDecoder TimeOfDay
170171time _ = mcsToTimeOfDay <$> getInt64BE
171172
173+ {-# INLINE timetz #-}
174+ timetz :: FieldDecoder TimeOfDay
175+ timetz _ = do
176+ t <- getInt64BE
177+ skipBytes 4
178+ return $ mcsToTimeOfDay t
179+
172180{-# INLINE timestamp #-}
173181timestamp :: FieldDecoder LocalTime
174182timestamp _ = microsToLocalTime <$> getInt64BE
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ module Database.PostgreSQL.Protocol.Codecs.Encoders
1414 , numeric
1515 , bsText
1616 , time
17+ , timetz
1718 , timestamp
1819 , timestamptz
1920 , uuid
@@ -48,7 +49,7 @@ bytea = putByteString
4849{-# INLINE char #-}
4950char :: Char -> Encode
5051char c
51- | ord(c) >= 128 = error " Character code must be below 128"
52+ | ord c >= 128 = error " Character code must be below 128"
5253 | otherwise = (putWord8 . fromIntegral . ord) c
5354
5455{-# INLINE date #-}
@@ -109,6 +110,10 @@ bsText = putByteString
109110time :: TimeOfDay -> Encode
110111time = putInt64BE . timeOfDayToMcs
111112
113+ {-# INLINE timetz #-}
114+ timetz :: TimeOfDay -> Encode
115+ timetz t = putInt64BE (timeOfDayToMcs t) <> putInt32BE 0
116+
112117{-# INLINE timestamp #-}
113118timestamp :: LocalTime -> Encode
114119timestamp = putInt64BE . localTimeToMicros
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ module Database.PostgreSQL.Protocol.Codecs.PgTypes
1919 , numeric
2020 , text
2121 , time
22+ , timetz
2223 , timestamp
2324 , timestamptz
2425 , uuid
@@ -92,6 +93,9 @@ text = mkOids 25 1009
9293time :: Oids
9394time = mkOids 1083 1183
9495
96+ timetz :: Oids
97+ timetz = mkOids 1266 1270
98+
9599timestamp :: Oids
96100timestamp = mkOids 1114 1115
97101
Original file line number Diff line number Diff line change @@ -7,8 +7,10 @@ module Database.PostgreSQL.Protocol.Codecs.Time
77 , microsToUTC
88 , microsToLocalTime
99 , mcsToTimeOfDay
10+ , mcsToDiffTime
1011 , intervalToDiffTime
1112 , diffTimeToInterval
13+ , diffTimeToMcs
1214 ) where
1315
1416import Data.Int (Int64 , Int32 , Int64 )
Original file line number Diff line number Diff line change @@ -111,6 +111,7 @@ testCodecsEncodeDecode = testGroup "Codecs property 'encode . decode = id'"
111111 , mkCodecTest " numeric" PGT. numeric PE. numeric PD. numeric
112112 , mkCodecTest " text" PGT. text PE. bsText PD. bsText
113113 , mkCodecTest " time" PGT. time PE. time PD. time
114+ , mkCodecTest " timetz" PGT. timetz PE. timetz PD. timetz
114115 , mkCodecTest " timestamp" PGT. timestamp PE. timestamp PD. timestamp
115116 , mkCodecTest " timestamptz" PGT. timestamptz PE. timestamptz PD. timestamptz
116117 , mkCodecTest " uuid" PGT. uuid PE. uuid PD. uuid
You can’t perform that action at this time.
0 commit comments