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
18
18
, numeric
19
19
, bsText
20
20
, time
21
+ , timetz
21
22
, timestamp
22
23
, timestamptz
23
24
, uuid
@@ -169,6 +170,13 @@ bsText = getByteString
169
170
time :: FieldDecoder TimeOfDay
170
171
time _ = mcsToTimeOfDay <$> getInt64BE
171
172
173
+ {-# INLINE timetz #-}
174
+ timetz :: FieldDecoder TimeOfDay
175
+ timetz _ = do
176
+ t <- getInt64BE
177
+ skipBytes 4
178
+ return $ mcsToTimeOfDay t
179
+
172
180
{-# INLINE timestamp #-}
173
181
timestamp :: FieldDecoder LocalTime
174
182
timestamp _ = microsToLocalTime <$> getInt64BE
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ module Database.PostgreSQL.Protocol.Codecs.Encoders
14
14
, numeric
15
15
, bsText
16
16
, time
17
+ , timetz
17
18
, timestamp
18
19
, timestamptz
19
20
, uuid
@@ -48,7 +49,7 @@ bytea = putByteString
48
49
{-# INLINE char #-}
49
50
char :: Char -> Encode
50
51
char c
51
- | ord(c) >= 128 = error " Character code must be below 128"
52
+ | ord c >= 128 = error " Character code must be below 128"
52
53
| otherwise = (putWord8 . fromIntegral . ord) c
53
54
54
55
{-# INLINE date #-}
@@ -109,6 +110,10 @@ bsText = putByteString
109
110
time :: TimeOfDay -> Encode
110
111
time = putInt64BE . timeOfDayToMcs
111
112
113
+ {-# INLINE timetz #-}
114
+ timetz :: TimeOfDay -> Encode
115
+ timetz t = putInt64BE (timeOfDayToMcs t) <> putInt32BE 0
116
+
112
117
{-# INLINE timestamp #-}
113
118
timestamp :: LocalTime -> Encode
114
119
timestamp = putInt64BE . localTimeToMicros
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ module Database.PostgreSQL.Protocol.Codecs.PgTypes
19
19
, numeric
20
20
, text
21
21
, time
22
+ , timetz
22
23
, timestamp
23
24
, timestamptz
24
25
, uuid
@@ -92,6 +93,9 @@ text = mkOids 25 1009
92
93
time :: Oids
93
94
time = mkOids 1083 1183
94
95
96
+ timetz :: Oids
97
+ timetz = mkOids 1266 1270
98
+
95
99
timestamp :: Oids
96
100
timestamp = mkOids 1114 1115
97
101
Original file line number Diff line number Diff line change @@ -7,8 +7,10 @@ module Database.PostgreSQL.Protocol.Codecs.Time
7
7
, microsToUTC
8
8
, microsToLocalTime
9
9
, mcsToTimeOfDay
10
+ , mcsToDiffTime
10
11
, intervalToDiffTime
11
12
, diffTimeToInterval
13
+ , diffTimeToMcs
12
14
) where
13
15
14
16
import 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'"
111
111
, mkCodecTest " numeric" PGT. numeric PE. numeric PD. numeric
112
112
, mkCodecTest " text" PGT. text PE. bsText PD. bsText
113
113
, mkCodecTest " time" PGT. time PE. time PD. time
114
+ , mkCodecTest " timetz" PGT. timetz PE. timetz PD. timetz
114
115
, mkCodecTest " timestamp" PGT. timestamp PE. timestamp PD. timestamp
115
116
, mkCodecTest " timestamptz" PGT. timestamptz PE. timestamptz PD. timestamptz
116
117
, mkCodecTest " uuid" PGT. uuid PE. uuid PD. uuid
You can’t perform that action at this time.
0 commit comments