kudu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject [4/4] kudu git commit: python: fix py2.6 incompatibility in unixtime_micros support
Date Thu, 08 Dec 2016 03:43:56 GMT
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 <jtbirdsell@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 <todd@apache.org>
Authored: Wed Dec 7 16:07:34 2016 -0800
Committer: Todd Lipcon <todd@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):
     """


Mime
View raw message