@@ -13,6 +13,8 @@ module Database.PostgreSQL.Protocol.Codecs.Encoders
|
13 | 13 | , bsJsonBytes
|
14 | 14 | , numeric
|
15 | 15 | , bsText
|
| 16 | +, time |
| 17 | +, timetz |
16 | 18 | , timestamp
|
17 | 19 | , timestamptz
|
18 | 20 | , uuid
|
@@ -23,7 +25,7 @@ import Data.Char (ord)
|
23 | 25 | import Data.Int (Int16, Int32, Int64)
|
24 | 26 | import Data.Monoid ((<>))
|
25 | 27 | import Data.Scientific (Scientific)
|
26 |
| -import Data.Time (Day, UTCTime, LocalTime, DiffTime) |
| 28 | +import Data.Time (Day, UTCTime, LocalTime, DiffTime, TimeOfDay) |
27 | 29 | import Data.UUID (UUID, toWords)
|
28 | 30 |
|
29 | 31 | import Database.PostgreSQL.Protocol.Store.Encode
|
@@ -47,7 +49,7 @@ bytea = putByteString
|
47 | 49 | {-# INLINE char #-}
|
48 | 50 | char :: Char -> Encode
|
49 | 51 | char c
|
50 |
| -| ord(c) >= 128 = error "Character code must be below 128" |
| 52 | +| ord c >= 128 = error "Character code must be below 128" |
51 | 53 | | otherwise = (putWord8 . fromIntegral . ord) c
|
52 | 54 |
|
53 | 55 | {-# INLINE date #-}
|
@@ -104,6 +106,14 @@ numeric n =
|
104 | 106 | bsText :: ByteString -> Encode
|
105 | 107 | bsText = putByteString
|
106 | 108 |
|
| 109 | +{-# INLINE time #-} |
| 110 | +time :: TimeOfDay -> Encode |
| 111 | +time = putInt64BE . timeOfDayToMcs |
| 112 | + |
| 113 | +{-# INLINE timetz #-} |
| 114 | +timetz :: TimeOfDay -> Encode |
| 115 | +timetz t = putInt64BE (timeOfDayToMcs t) <> putInt32BE 0 |
| 116 | + |
107 | 117 | {-# INLINE timestamp #-}
|
108 | 118 | timestamp :: LocalTime -> Encode
|
109 | 119 | timestamp = putInt64BE . localTimeToMicros
|
|
0 commit comments