You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2016/12/08 03:43:56 UTC

[4/4] kudu git commit: python: fix py2.6 incompatibility in unixtime_micros support

python: fix py2.6 incompatibility in unixtime_micros support

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 <jt...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/85de6862
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/85de6862
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/85de6862

Branch: refs/heads/master
Commit: 85de6862204d79b30ea3684a276d00a32651937c
Parents: bec5f9b
Author: Todd Lipcon <to...@apache.org>
Authored: Wed Dec 7 16:07:34 2016 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Thu Dec 8 03:41:32 2016 +0000

----------------------------------------------------------------------
 python/kudu/util.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/85de6862/python/kudu/util.py
----------------------------------------------------------------------
diff --git a/python/kudu/util.py b/python/kudu/util.py
index f290425..350a011 100644
--- a/python/kudu/util.py
+++ b/python/kudu/util.py
@@ -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):
     """