Skip to content

Commit

Permalink
python: fix py2.6 incompatibility in unixtime_micros support
Browse files Browse the repository at this point in the history
Python 2.6 doesn't have the timedelta.total_seconds() function that's
used when converting time objects to unixtime_micros. This replaces the
function with a simple calculation as recommended by the docs.

Change-Id: Ib56e586e19e549b123b43b301d73742616bb7b0e
Reviewed-on: http://gerrit.cloudera.org:8080/5409
Tested-by: Kudu Jenkins
Reviewed-by: Jordan Birdsell <[email protected]>
  • Loading branch information
toddlipcon committed Dec 8, 2016
1 parent bec5f9b commit 85de686
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions python/kudu/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ def to_unixtime_micros(timestamp, format = "%Y-%m-%dT%H:%M:%S.%f"):
else:
timestamp = timestamp.replace(tzinfo=utc)

# Return the unixtime_micros for the provided datetime and locale
return int((timestamp - _epoch()).total_seconds() * 1000000)
# Return the unixtime_micros for the provided datetime and locale.
# Avoid timedelta.total_seconds() for py2.6 compatibility.
td = timestamp - _epoch()
td_micros = td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6
return int(td_micros)

def from_unixtime_micros(unixtime_micros):
"""
Expand Down

0 comments on commit 85de686

Please sign in to comment.