Display times in local tz
By default, display times using the local timezone. Add timezone info to time displays where space permits. Add an option to restore the current behavior where times are displayed in UTC. Change-Id: I6035b6277dc49774537a762b2946c56a3b8dec17 Co-Authored-By: Bradley Jones <jones.bradley@me.com>
This commit is contained in:
parent
c5f7246717
commit
9d99e078f1
@ -146,6 +146,10 @@ commentlinks:
|
||||
# default. To disable this behavior, uncomment the following line:
|
||||
# thread-changes: false
|
||||
|
||||
# Times are displayed in the local timezone by default. To display
|
||||
# them in UTC instead, uncomment the following line:
|
||||
# display-times-in-utc: true
|
||||
|
||||
# Uncomment the following lines to Hide comments by default that match
|
||||
# certain criteria. You can toggle their display with 't'. Currently
|
||||
# the only supported criterion is "author".
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import argparse
|
||||
import dateutil
|
||||
import logging
|
||||
import os
|
||||
import Queue
|
||||
@ -441,6 +442,13 @@ class App(object):
|
||||
self.log.debug("Open URL %s" % url)
|
||||
webbrowser.open_new_tab(url)
|
||||
|
||||
def time(self, dt):
|
||||
utc = dt.replace(tzinfo=dateutil.tz.tzutc())
|
||||
if self.config.utc:
|
||||
return utc
|
||||
local = utc.astimezone(dateutil.tz.tzlocal())
|
||||
return local
|
||||
|
||||
def version():
|
||||
return "Gertty version: %s" % gertty.version.version_info.version_string()
|
||||
|
||||
|
@ -111,6 +111,7 @@ class ConfigSchema(object):
|
||||
'diff-view': str,
|
||||
'hide-comments': self.hide_comments,
|
||||
'thread-changes': bool,
|
||||
'display-times-in-utc': bool
|
||||
})
|
||||
return schema
|
||||
|
||||
@ -212,6 +213,7 @@ class Config(object):
|
||||
self.hide_comments.append(re.compile(h['author']))
|
||||
|
||||
self.thread_changes = self.config.get('thread-changes', True)
|
||||
self.utc = self.config.get('display-times-in-utc', False)
|
||||
|
||||
def getServer(self, name=None):
|
||||
for server in self.config['servers']:
|
||||
|
@ -360,6 +360,7 @@ class ChangeMessageBox(mywid.HyperText):
|
||||
|
||||
def refresh(self, message):
|
||||
self.message_created = message.created
|
||||
created = self.app.time(message.created)
|
||||
lines = message.message.split('\n')
|
||||
if message.draft:
|
||||
lines.insert(0, '')
|
||||
@ -367,7 +368,7 @@ class ChangeMessageBox(mywid.HyperText):
|
||||
text = [('change-message-name', message.author_name),
|
||||
('change-message-header', ': '+lines.pop(0)),
|
||||
('change-message-header',
|
||||
message.created.strftime(' (%Y-%m-%d %H:%M:%S%z)'))]
|
||||
created.strftime(' (%Y-%m-%d %H:%M:%S%z)'))]
|
||||
if message.draft and not message.pending:
|
||||
text.append(('change-message-draft', ' (draft)'))
|
||||
if lines and lines[-1]:
|
||||
@ -570,8 +571,8 @@ class ChangeView(urwid.WidgetWrap):
|
||||
self.project_label.set_text(('change-data', change.project.name))
|
||||
self.branch_label.set_text(('change-data', change.branch))
|
||||
self.topic_label.set_text(('change-data', self.topic))
|
||||
self.created_label.set_text(('change-data', str(change.created)))
|
||||
self.updated_label.set_text(('change-data', str(change.updated)))
|
||||
self.created_label.set_text(('change-data', str(self.app.time(change.created))))
|
||||
self.updated_label.set_text(('change-data', str(self.app.time(change.updated))))
|
||||
self.status_label.set_text(('change-data', change.status))
|
||||
self.commit_message.set_text(change.revisions[-1].message)
|
||||
|
||||
|
@ -59,9 +59,10 @@ class ChangeRow(urwid.Button):
|
||||
def selectable(self):
|
||||
return True
|
||||
|
||||
def __init__(self, change, categories, project=False, owner=False,
|
||||
def __init__(self, app, change, categories, project=False, owner=False,
|
||||
updated=False, callback=None):
|
||||
super(ChangeRow, self).__init__('', on_press=callback, user_data=change.key)
|
||||
self.app = app
|
||||
self.change_key = change.key
|
||||
self.subject = urwid.Text(u'', wrap='clip')
|
||||
self.number = urwid.Text(u'')
|
||||
@ -95,10 +96,12 @@ class ChangeRow(urwid.Button):
|
||||
self.number.set_text(str(change.number))
|
||||
self.project.set_text(change.project.name.split('/')[-1])
|
||||
self.owner.set_text(change.owner_name)
|
||||
if datetime.date.today() == change.updated.date():
|
||||
self.updated.set_text(change.updated.strftime("%I:%M %p").upper())
|
||||
today = self.app.time(datetime.datetime.utcnow()).date()
|
||||
updated_time = self.app.time(change.updated)
|
||||
if today == updated_time.date():
|
||||
self.updated.set_text(updated_time.strftime("%I:%M %p").upper())
|
||||
else:
|
||||
self.updated.set_text(change.updated.strftime("%Y-%m-%d"))
|
||||
self.updated.set_text(updated_time.strftime("%Y-%m-%d"))
|
||||
del self.columns.contents[self.num_columns:]
|
||||
for category in categories:
|
||||
v = change.getMaxForCategory(category)
|
||||
@ -226,9 +229,11 @@ class ChangeListView(urwid.WidgetWrap):
|
||||
for change in change_list:
|
||||
row = self.change_rows.get(change.key)
|
||||
if not row:
|
||||
row = ChangeRow(change, self.categories, self.display_project,
|
||||
self.display_owner, self.display_updated,
|
||||
callback=self.onSelect)
|
||||
row = ChangeRow(self.app, change, self.categories,
|
||||
self.display_project,
|
||||
self.display_owner,
|
||||
self.display_updated,
|
||||
callback=self.onSelect)
|
||||
self.listbox.body.insert(i, row)
|
||||
self.change_rows[change.key] = row
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user