# HG changeset patch # User Daniel Dourvaris # Date 2016-06-09 02:49:33 # Node ID bb64dc25f511bde0ee176f7da2fb58711ac92797 # Parent 3953c69fb3c80f623b5ea0288cc0b8272d3fee5d datetimes: fix datetimes to work across app, converting to utc 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)}
- ${h.age_component(comment.modified_at)} + ${h.age_component(comment.modified_at, time_is_local=True)}
%if comment.pull_request: @@ -80,7 +80,7 @@ ${base.gravatar_with_user(comment.author.email, 16)}
- ${h.age_component(comment.modified_at)} + ${h.age_component(comment.modified_at, time_is_local=True)}
%if comment.status_change: diff --git a/rhodecode/templates/data_table/_dt_elements.html b/rhodecode/templates/data_table/_dt_elements.html --- a/rhodecode/templates/data_table/_dt_elements.html +++ b/rhodecode/templates/data_table/_dt_elements.html @@ -243,7 +243,7 @@ <%def name="gist_created(created_on)">
- ${h.age_component(created_on)} + ${h.age_component(created_on, time_is_local=True)}
@@ -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 @@ -289,7 +289,7 @@ <%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 name="pullrequest_author(full_contact)"> diff --git a/rhodecode/templates/followers/followers_data.html b/rhodecode/templates/followers/followers_data.html --- a/rhodecode/templates/followers/followers_data.html +++ b/rhodecode/templates/followers/followers_data.html @@ -11,7 +11,7 @@ ${base.gravatar_with_user(f.user.email, 16)} - ${h.age_component(f.follows_from)} + ${h.age_component(f.follows_from, time_is_local=True)} % endfor diff --git a/rhodecode/templates/forks/forks_data.html b/rhodecode/templates/forks/forks_data.html --- a/rhodecode/templates/forks/forks_data.html +++ b/rhodecode/templates/forks/forks_data.html @@ -22,7 +22,7 @@
${f.description}
- ${h.age_component(f.created_on)} + ${h.age_component(f.created_on, time_is_local=True)}
${h.literal(h.action_parser(entry)[1]())}
- ${h.age_component(entry.action_date)} + ${h.age_component(entry.action_date, time_is_local=True)}
%endfor diff --git a/rhodecode/templates/search/search_commit.html b/rhodecode/templates/search/search_commit.html --- a/rhodecode/templates/search/search_commit.html +++ b/rhodecode/templates/search/search_commit.html @@ -46,7 +46,7 @@ %endif - ${h.age_component(h.time_to_datetime(entry['date']))} + ${h.age_component(h.time_to_utcdatetime(entry['date']))}