Skip to content

Commit c102479

Browse files
committed
feat(datatype): support timetz
1 parent 71f87f1 commit c102479

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

redshift_connector/utils/type_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,26 @@ def time_in(data: bytes, offset: int, length: int) -> time:
219219
return time(hour, minute, int(sec), int((sec - int(sec)) * 1000000))
220220

221221

222+
def timetz_in(data: bytes, offset: int, length: int) -> time:
223+
hour: int = int(data[offset : offset + 2])
224+
minute: int = int(data[offset + 3 : offset + 5])
225+
sec: Decimal = Decimal(data[offset + 6 : offset + 8].decode(_client_encoding))
226+
microsec: int = int((sec - int(sec)) * 1000000)
227+
228+
if length != 8:
229+
idx_tz: int = offset + 8
230+
# if microsec present, they start with '.'
231+
if data[idx_tz : idx_tz + 1] == b".":
232+
end_microseconds: int = length + offset
233+
for idx in range(idx_tz + 1, len(data)):
234+
if data[idx] == 43 or data[idx] == 45: # +/- char indicates start of tz offset
235+
end_microseconds = idx
236+
break
237+
238+
microsec += int(data[idx_tz + 1 : end_microseconds])
239+
return time(hour, minute, int(sec), microsec, tzinfo=Timezone.utc)
240+
241+
222242
def date_in(data: bytes, offset: int, length: int):
223243
d = data[offset : offset + length].decode(_client_encoding)
224244
try:
@@ -307,6 +327,7 @@ def date_in(data: bytes, offset: int, length: int):
307327
# 1186: (FC_BINARY, interval_recv_integer),
308328
# 1231: (FC_TEXT, array_in), # NUMERIC[]
309329
# 1263: (FC_BINARY, array_recv), # cstring[]
330+
1266: (FC_TEXT, timetz_in), # timetz
310331
1700: (FC_TEXT, numeric_in), # NUMERIC
311332
# 2275: (FC_BINARY, text_recv), # cstring
312333
# 2950: (FC_BINARY, uuid_recv), # uuid

0 commit comments

Comments
 (0)