You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ty...@apache.org on 2015/08/07 22:46:28 UTC

cassandra git commit: cqlsh: Fix timestamps before 1970 on Windows

Repository: cassandra
Updated Branches:
  refs/heads/cassandra-2.1 34193ee76 -> 1ecc9cd61


cqlsh: Fix timestamps before 1970 on Windows

This also has the side effect of displaying timestamps in the UTC
timezone instead of the local timezone.

Patch by Paulo Motta; reviewed by Tyler Hobbs for CASSANDRA-10000


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

Branch: refs/heads/cassandra-2.1
Commit: 1ecc9cd61e376e57a26042b5ea7e57142dd8a247
Parents: 34193ee
Author: Paulo Motta <pa...@gmail.com>
Authored: Fri Aug 7 15:45:16 2015 -0500
Committer: Tyler Hobbs <ty...@gmail.com>
Committed: Fri Aug 7 15:45:16 2015 -0500

----------------------------------------------------------------------
 NEWS.txt                     |  4 ++++
 pylib/cqlshlib/formatting.py | 19 ++++---------------
 pylib/cqlshlib/util.py       | 15 +++++++++++++++
 3 files changed, 23 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/1ecc9cd6/NEWS.txt
----------------------------------------------------------------------
diff --git a/NEWS.txt b/NEWS.txt
index dec3e99..0b64e31 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -19,10 +19,13 @@ using the provided 'sstableupgrade' tool.
 
 Upgrading
 ---------
+    - cqlsh will now display timestamps with a UTC timezone. Previously,
+      timestamps were displayed with the local timezone.
     - Commit log files are no longer recycled by default, due to negative
       performance implications. This can be enabled again with the 
       commitlog_segment_recycling option in your cassandra.yaml 
 
+
 2.1.8
 =====
 
@@ -31,6 +34,7 @@ Upgrading
     - Nothing specific to this release, but please see 2.1 if you are upgrading
       from a previous version.
 
+
 2.1.7
 =====
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1ecc9cd6/pylib/cqlshlib/formatting.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/formatting.py b/pylib/cqlshlib/formatting.py
index 2a99e23..37bd361 100644
--- a/pylib/cqlshlib/formatting.py
+++ b/pylib/cqlshlib/formatting.py
@@ -23,6 +23,8 @@ from collections import defaultdict
 from . import wcwidth
 from .displaying import colorme, FormattedValue, DEFAULT_VALUE_COLORS
 from cassandra.cqltypes import EMPTY
+from cassandra.util import datetime_from_timestamp
+from util import UTC
 
 unicode_controlchars_re = re.compile(r'[\x00-\x31\x7f-\xa0]')
 controlchars_re = re.compile(r'[\x00-\x31\x7f-\xff]')
@@ -175,21 +177,8 @@ def format_value_timestamp(val, colormap, time_format, quote=False, **_):
 formatter_for('datetime')(format_value_timestamp)
 
 def strftime(time_format, seconds):
-    local = time.localtime(seconds)
-    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:
-        return formatted
-    # 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)
-    return formatted[:-5] + sign + '{0:0=2}{1:0=2}'.format(hours, minutes)
+    tzless_dt = datetime_from_timestamp(seconds)
+    return tzless_dt.replace(tzinfo=UTC()).strftime(time_format)
 
 @formatter_for('str')
 def format_value_text(val, encoding, colormap, quote=False, **_):

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1ecc9cd6/pylib/cqlshlib/util.py
----------------------------------------------------------------------
diff --git a/pylib/cqlshlib/util.py b/pylib/cqlshlib/util.py
index bc58c8b..4273efc 100644
--- a/pylib/cqlshlib/util.py
+++ b/pylib/cqlshlib/util.py
@@ -16,6 +16,21 @@
 
 import codecs
 from itertools import izip
+from datetime import timedelta, tzinfo
+
+ZERO = timedelta(0)
+
+class UTC(tzinfo):
+    """UTC"""
+
+    def utcoffset(self, dt):
+        return ZERO
+
+    def tzname(self, dt):
+        return "UTC"
+
+    def dst(self, dt):
+        return ZERO
 
 
 def split_list(items, pred):