mirror of https://github.com/apache/cassandra
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
This commit is contained in:
parent
34193ee766
commit
1ecc9cd61e
4
NEWS.txt
4
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
|
||||
=====
|
||||
|
||||
|
|
|
|||
|
|
@ -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, **_):
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue