Skip to content

Commit

Permalink
Merge pull request #3 from fishtown-analytics/fix/strftime-clib
Browse files Browse the repository at this point in the history
fix for inconsistent c strftime implementations
  • Loading branch information
KAllan357 authored Feb 28, 2018
2 parents 6da0bcd + 891b8bb commit 4c3a143
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions tap_codat/transform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pendulum
from singer.utils import strftime
from singer.utils import strftime as singer_strftime


class DictKey(object):
Expand Down Expand Up @@ -69,12 +69,31 @@ def _check_type(item, path, path_idx):
raise TransformationException(item, path, path_idx)


def safe_strftime(dt):
# Different implementations of the C strftime lib
# will render out years differently. This function
# tries to use the Singer strftime func, then falls
# back to a different implementation.
#
# If the strftime lib is different than the expected version,
# then the resulting date will look like
#
# 4Y-01-01 12:00:00...
#
# This code catches this failure mode, and use an alternative fmt string

res = singer_strftime(dt)
if res.startswith('4Y'):
res = dt.strftime('%Y-%m-%dT%H:%M:%S.%fZ')

return res

def _transform_impl(item, path, path_idx=0):
if not item:
return item
if path_idx == len(path):
dt = pendulum.parse(item).in_timezone("UTC")
return dt.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
return safe_strftime(dt)
_check_type(item, path, path_idx)
path_item = path[path_idx]
for k, v in path_item.iterate(item):
Expand Down

0 comments on commit 4c3a143

Please sign in to comment.