datetimes: fix datetimes to work across app, converting to utc
This commit is contained in:
parent
bf510fd33c
commit
52cea90a4b
12 changed files with 36 additions and 19 deletions
|
|
@ -71,8 +71,8 @@ from rhodecode.lib.annotate import annotate_highlight
|
|||
from rhodecode.lib.action_parser import action_parser
|
||||
from rhodecode.lib.utils import repo_name_slug, get_custom_lexer
|
||||
from rhodecode.lib.utils2 import str2bool, safe_unicode, safe_str, \
|
||||
get_commit_safe, datetime_to_time, time_to_datetime, AttributeDict, \
|
||||
safe_int, md5, md5_safe
|
||||
get_commit_safe, datetime_to_time, time_to_datetime, time_to_utcdatetime, \
|
||||
AttributeDict, safe_int, md5, md5_safe
|
||||
from rhodecode.lib.markup_renderer import MarkupRenderer
|
||||
from rhodecode.lib.vcs.exceptions import CommitDoesNotExistError
|
||||
from rhodecode.lib.vcs.backends.base import BaseChangeset, EmptyCommit
|
||||
|
|
@ -649,13 +649,20 @@ short_id = lambda x: x[:12]
|
|||
hide_credentials = lambda x: ''.join(credentials_filter(x))
|
||||
|
||||
|
||||
def age_component(datetime_iso, value=None):
|
||||
def age_component(datetime_iso, value=None, time_is_local=False):
|
||||
title = value or format_date(datetime_iso)
|
||||
|
||||
# detect if we have a timezone info, if not assume UTC
|
||||
# detect if we have a timezone info, otherwise, add it
|
||||
if isinstance(datetime_iso, datetime) and not datetime_iso.tzinfo:
|
||||
tzinfo = '+00:00'
|
||||
|
||||
if time_is_local:
|
||||
tzinfo = time.strftime("+%H:%M",
|
||||
time.gmtime(
|
||||
(datetime.now() - datetime.utcnow()).seconds + 1
|
||||
)
|
||||
)
|
||||
|
||||
return literal(
|
||||
'<time class="timeago tooltip" '
|
||||
'title="{1}" datetime="{0}{2}">{1}</time>'.format(
|
||||
|
|
|
|||
|
|
@ -608,6 +608,16 @@ def time_to_datetime(tm):
|
|||
return datetime.datetime.fromtimestamp(tm)
|
||||
|
||||
|
||||
def time_to_utcdatetime(tm):
|
||||
if tm:
|
||||
if isinstance(tm, basestring):
|
||||
try:
|
||||
tm = float(tm)
|
||||
except ValueError:
|
||||
return
|
||||
return datetime.datetime.utcfromtimestamp(tm)
|
||||
|
||||
|
||||
MENTIONS_REGEX = re.compile(
|
||||
# ^@ or @ without any special chars in front
|
||||
r'(?:^@|[^a-zA-Z0-9\-\_\.]@)'
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ var AgeModule = (function () {
|
|||
|
||||
},
|
||||
createTimeComponent: function(dateTime, text) {
|
||||
return '<time class="timeago tooltip" title="{1}" datetime="{0}">{1}</time>'.format(dateTime, text);
|
||||
return '<time class="timeago tooltip" title="{1}" datetime="{0}+0000">{1}</time>'.format(dateTime, text);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@
|
|||
%if c.gist.gist_expires == -1:
|
||||
${_('never')}
|
||||
%else:
|
||||
${h.age_component(h.time_to_datetime(c.gist.gist_expires))}
|
||||
${h.age_component(h.time_to_utcdatetime(c.gist.gist_expires))}
|
||||
%endif
|
||||
</span>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@
|
|||
${_('expires')}: ${_('never')}
|
||||
%else:
|
||||
%if auth_token.expired:
|
||||
${_('expired')}: ${h.age_component(h.time_to_datetime(auth_token.expires))}
|
||||
${_('expired')}: ${h.age_component(h.time_to_utcdatetime(auth_token.expires))}
|
||||
%else:
|
||||
${_('expires')}: ${h.age_component(h.time_to_datetime(auth_token.expires))}
|
||||
${_('expires')}: ${h.age_component(h.time_to_utcdatetime(auth_token.expires))}
|
||||
%endif
|
||||
%endif
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@
|
|||
${_('expires')}: ${_('never')}
|
||||
%else:
|
||||
%if auth_token.expired:
|
||||
${_('expired')}: ${h.age_component(h.time_to_datetime(auth_token.expires))}
|
||||
${_('expired')}: ${h.age_component(h.time_to_utcdatetime(auth_token.expires))}
|
||||
%else:
|
||||
${_('expires')}: ${h.age_component(h.time_to_datetime(auth_token.expires))}
|
||||
${_('expires')}: ${h.age_component(h.time_to_utcdatetime(auth_token.expires))}
|
||||
%endif
|
||||
%endif
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
${base.gravatar_with_user(comment.author.email, 16)}
|
||||
</div>
|
||||
<div class="date">
|
||||
${h.age_component(comment.modified_at)}
|
||||
${h.age_component(comment.modified_at, time_is_local=True)}
|
||||
</div>
|
||||
<div class="status-change">
|
||||
%if comment.pull_request:
|
||||
|
|
@ -80,7 +80,7 @@
|
|||
${base.gravatar_with_user(comment.author.email, 16)}
|
||||
</div>
|
||||
<div class="date">
|
||||
${h.age_component(comment.modified_at)}
|
||||
${h.age_component(comment.modified_at, time_is_local=True)}
|
||||
</div>
|
||||
%if comment.status_change:
|
||||
<span class="changeset-status-container">
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@
|
|||
|
||||
<%def name="gist_created(created_on)">
|
||||
<div class="created">
|
||||
${h.age_component(created_on)}
|
||||
${h.age_component(created_on, time_is_local=True)}
|
||||
</div>
|
||||
</%def>
|
||||
|
||||
|
|
@ -252,7 +252,7 @@
|
|||
%if expires == -1:
|
||||
${_('never')}
|
||||
%else:
|
||||
${h.age_component(h.time_to_datetime(expires))}
|
||||
${h.age_component(h.time_to_utcdatetime(expires))}
|
||||
%endif
|
||||
</div>
|
||||
</%def>
|
||||
|
|
@ -289,7 +289,7 @@
|
|||
</%def>
|
||||
|
||||
<%def name="pullrequest_updated_on(updated_on)">
|
||||
${h.age_component(h.time_to_datetime(updated_on))}
|
||||
${h.age_component(h.time_to_utcdatetime(updated_on))}
|
||||
</%def>
|
||||
|
||||
<%def name="pullrequest_author(full_contact)">
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
${base.gravatar_with_user(f.user.email, 16)}
|
||||
</td>
|
||||
<td class="td-time follower_date">
|
||||
${h.age_component(f.follows_from)}
|
||||
${h.age_component(f.follows_from, time_is_local=True)}
|
||||
</td>
|
||||
</tr>
|
||||
% endfor
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
<div class="truncate">${f.description}</div>
|
||||
</td>
|
||||
<td class="td-time follower_date">
|
||||
${h.age_component(f.created_on)}
|
||||
${h.age_component(f.created_on, time_is_local=True)}
|
||||
</td>
|
||||
<td class="td-compare">
|
||||
<a title="${_('Compare fork with %s' % c.repo_name)}"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
</div>
|
||||
<div class="journal_action_params">${h.literal(h.action_parser(entry)[1]())}</div>
|
||||
<div class="date">
|
||||
${h.age_component(entry.action_date)}
|
||||
${h.age_component(entry.action_date, time_is_local=True)}
|
||||
</div>
|
||||
%endfor
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@
|
|||
%endif
|
||||
</td>
|
||||
<td class="td-time">
|
||||
${h.age_component(h.time_to_datetime(entry['date']))}
|
||||
${h.age_component(h.time_to_utcdatetime(entry['date']))}
|
||||
</td>
|
||||
|
||||
<td class="td-user author">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue