Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit ddc46ce

Browse files
authored
convert time with timezone columns to UTC (#27)
1 parent 2890000 commit ddc46ce

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tap_postgres/sync_strategies/logical_replication.py

+17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import singer
55
import datetime
66
import time
7+
import pytz
78
import decimal
89
from singer import utils, get_bookmark
910
import singer.metadata as metadata
@@ -203,6 +204,22 @@ def selected_value_to_singer_value_impl(elem, og_sql_datatype, conn_info):
203204
return elem.isoformat() + 'T00:00:00+00:00'
204205
return parse(elem).isoformat() + "+00:00"
205206
if sql_datatype == 'time with time zone':
207+
'''time with time zone values will be converted to UTC and time zone dropped'''
208+
# Replace hour=24 with hour=0
209+
if elem.startswith('24'): elem = elem.replace('24','00',1)
210+
# convert to UTC
211+
elem = elem + '00'
212+
elem_obj = datetime.datetime.strptime(elem, '%H:%M:%S%z')
213+
if elem_obj.utcoffset() != datetime.timedelta(seconds=0):
214+
LOGGER.warning('time with time zone values are converted to UTC'.format(og_sql_datatype))
215+
elem_obj = elem_obj.astimezone(pytz.utc)
216+
# drop time zone
217+
elem = elem_obj.strftime('%H:%M:%S')
218+
return parse(elem).isoformat().split('T')[1]
219+
if sql_datatype == 'time without time zone':
220+
# Replace hour=24 with hour=0
221+
if elem.startswith('24'):
222+
elem = elem.replace('24','00',1)
206223
return parse(elem).isoformat().split('T')[1]
207224
if sql_datatype == 'bit':
208225
#for arrays, elem will == True

0 commit comments

Comments
 (0)