diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -71,8 +71,8 @@ from rhodecode.lib.annotate import annot 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( ''.format( diff --git a/rhodecode/lib/utils2.py b/rhodecode/lib/utils2.py --- a/rhodecode/lib/utils2.py +++ b/rhodecode/lib/utils2.py @@ -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\-\_\.]@)' diff --git a/rhodecode/public/js/src/plugins/jquery.timeago-extension.js b/rhodecode/public/js/src/plugins/jquery.timeago-extension.js --- a/rhodecode/public/js/src/plugins/jquery.timeago-extension.js +++ b/rhodecode/public/js/src/plugins/jquery.timeago-extension.js @@ -190,7 +190,7 @@ var AgeModule = (function () { }, createTimeComponent: function(dateTime, text) { - return ''.format(dateTime, text); + return ''.format(dateTime, text); } } })(); diff --git a/rhodecode/templates/admin/gists/show.html b/rhodecode/templates/admin/gists/show.html --- a/rhodecode/templates/admin/gists/show.html +++ b/rhodecode/templates/admin/gists/show.html @@ -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 diff --git a/rhodecode/templates/admin/my_account/my_account_auth_tokens.html b/rhodecode/templates/admin/my_account/my_account_auth_tokens.html --- a/rhodecode/templates/admin/my_account/my_account_auth_tokens.html +++ b/rhodecode/templates/admin/my_account/my_account_auth_tokens.html @@ -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 diff --git a/rhodecode/templates/admin/users/user_edit_auth_tokens.html b/rhodecode/templates/admin/users/user_edit_auth_tokens.html --- a/rhodecode/templates/admin/users/user_edit_auth_tokens.html +++ b/rhodecode/templates/admin/users/user_edit_auth_tokens.html @@ -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 diff --git a/rhodecode/templates/changeset/changeset_file_comment.html b/rhodecode/templates/changeset/changeset_file_comment.html --- a/rhodecode/templates/changeset/changeset_file_comment.html +++ b/rhodecode/templates/changeset/changeset_file_comment.html @@ -12,7 +12,7 @@ ${base.gravatar_with_user(comment.author.email, 16)}