cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [4/4] git commit: cqlsh: fix timestamp formatting for tz info Patch by Aleksey Yeschenko, reviewed by brandonwilliams for CASSANDRA-4746
Date Tue, 30 Oct 2012 15:42:21 GMT
cqlsh: fix timestamp formatting for tz info
Patch by Aleksey Yeschenko, reviewed by brandonwilliams for
CASSANDRA-4746


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

Branch: refs/heads/trunk
Commit: d51643cad435ffcda77f7b877762998851abf948
Parents: a2a2251
Author: Brandon Williams <brandonwilliams@apache.org>
Authored: Fri Oct 26 08:45:27 2012 -0500
Committer: Brandon Williams <brandonwilliams@apache.org>
Committed: Fri Oct 26 08:48:31 2012 -0500

----------------------------------------------------------------------
 bin/cqlsh |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/d51643ca/bin/cqlsh
----------------------------------------------------------------------
diff --git a/bin/cqlsh b/bin/cqlsh
index 22edde6..1220c61 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -489,8 +489,22 @@ def format_value(val, casstype, output_encoding, addcolor=False, time_format='',
     elif casstype in ('DateType', 'TimeUUIDType'):
         if casstype == 'TimeUUIDType':
             val = unix_time_from_uuid1(val)
-        timestamp = time.localtime(val)
-        bval = time.strftime(time_format, timestamp)
+        local = time.localtime(val)
+        formatted = time.strftime(time_format, local)
+        if local.tm_isdst != 0:
+            offset = -time.altzone
+        else:
+            offset = -time.timezone
+        if formatted[-4] != '0000' or time_format[-2] != '%z' or offset == 0:
+            bval = formatted
+        else:
+            # deal with %z on platforms where it isn't supported. see CASSANDRA-4746.
+            if offset < 0:
+                sign = '-'
+            else:
+                sign = '+'
+            hours, minutes = divmod(abs(offset) / 60, 60)
+            bval = formatted[:-5] + sign + '{0:0=2}{1:0=2}'.format(hours, minutes)
         color = colormap['timestamp']
     elif casstype in ('LongType', 'Int32Type', 'IntegerType', 'CounterColumnType'):
         # base-10 only for now; support others?


Mime
View raw message