|
4 | 4 | import singer
|
5 | 5 | import datetime
|
6 | 6 | import time
|
| 7 | +import pytz |
7 | 8 | import decimal
|
8 | 9 | from singer import utils, get_bookmark
|
9 | 10 | import singer.metadata as metadata
|
@@ -203,6 +204,22 @@ def selected_value_to_singer_value_impl(elem, og_sql_datatype, conn_info):
|
203 | 204 | return elem.isoformat() + 'T00:00:00+00:00'
|
204 | 205 | return parse(elem).isoformat() + "+00:00"
|
205 | 206 | 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) |
206 | 223 | return parse(elem).isoformat().split('T')[1]
|
207 | 224 | if sql_datatype == 'bit':
|
208 | 225 | #for arrays, elem will == True
|
|
0 commit comments