##// END OF EJS Templates
datetimes: fix datetimes to work across app, converting to utc
dan -
r155:bb64dc25 default
parent child Browse files
Show More
@@ -71,8 +71,8 b' from rhodecode.lib.annotate import annot'
71 from rhodecode.lib.action_parser import action_parser
71 from rhodecode.lib.action_parser import action_parser
72 from rhodecode.lib.utils import repo_name_slug, get_custom_lexer
72 from rhodecode.lib.utils import repo_name_slug, get_custom_lexer
73 from rhodecode.lib.utils2 import str2bool, safe_unicode, safe_str, \
73 from rhodecode.lib.utils2 import str2bool, safe_unicode, safe_str, \
74 get_commit_safe, datetime_to_time, time_to_datetime, AttributeDict, \
74 get_commit_safe, datetime_to_time, time_to_datetime, time_to_utcdatetime, \
75 safe_int, md5, md5_safe
75 AttributeDict, safe_int, md5, md5_safe
76 from rhodecode.lib.markup_renderer import MarkupRenderer
76 from rhodecode.lib.markup_renderer import MarkupRenderer
77 from rhodecode.lib.vcs.exceptions import CommitDoesNotExistError
77 from rhodecode.lib.vcs.exceptions import CommitDoesNotExistError
78 from rhodecode.lib.vcs.backends.base import BaseChangeset, EmptyCommit
78 from rhodecode.lib.vcs.backends.base import BaseChangeset, EmptyCommit
@@ -649,13 +649,20 b' short_id = lambda x: x[:12]'
649 hide_credentials = lambda x: ''.join(credentials_filter(x))
649 hide_credentials = lambda x: ''.join(credentials_filter(x))
650
650
651
651
652 def age_component(datetime_iso, value=None):
652 def age_component(datetime_iso, value=None, time_is_local=False):
653 title = value or format_date(datetime_iso)
653 title = value or format_date(datetime_iso)
654
654
655 # detect if we have a timezone info, if not assume UTC
655 # detect if we have a timezone info, otherwise, add it
656 if isinstance(datetime_iso, datetime) and not datetime_iso.tzinfo:
656 if isinstance(datetime_iso, datetime) and not datetime_iso.tzinfo:
657 tzinfo = '+00:00'
657 tzinfo = '+00:00'
658
658
659 if time_is_local:
660 tzinfo = time.strftime("+%H:%M",
661 time.gmtime(
662 (datetime.now() - datetime.utcnow()).seconds + 1
663 )
664 )
665
659 return literal(
666 return literal(
660 '<time class="timeago tooltip" '
667 '<time class="timeago tooltip" '
661 'title="{1}" datetime="{0}{2}">{1}</time>'.format(
668 'title="{1}" datetime="{0}{2}">{1}</time>'.format(
@@ -608,6 +608,16 b' def time_to_datetime(tm):'
608 return datetime.datetime.fromtimestamp(tm)
608 return datetime.datetime.fromtimestamp(tm)
609
609
610
610
611 def time_to_utcdatetime(tm):
612 if tm:
613 if isinstance(tm, basestring):
614 try:
615 tm = float(tm)
616 except ValueError:
617 return
618 return datetime.datetime.utcfromtimestamp(tm)
619
620
611 MENTIONS_REGEX = re.compile(
621 MENTIONS_REGEX = re.compile(
612 # ^@ or @ without any special chars in front
622 # ^@ or @ without any special chars in front
613 r'(?:^@|[^a-zA-Z0-9\-\_\.]@)'
623 r'(?:^@|[^a-zA-Z0-9\-\_\.]@)'
@@ -190,7 +190,7 b' var AgeModule = (function () {'
190
190
191 },
191 },
192 createTimeComponent: function(dateTime, text) {
192 createTimeComponent: function(dateTime, text) {
193 return '<time class="timeago tooltip" title="{1}" datetime="{0}">{1}</time>'.format(dateTime, text);
193 return '<time class="timeago tooltip" title="{1}" datetime="{0}+0000">{1}</time>'.format(dateTime, text);
194 }
194 }
195 }
195 }
196 })();
196 })();
@@ -66,7 +66,7 b''
66 %if c.gist.gist_expires == -1:
66 %if c.gist.gist_expires == -1:
67 ${_('never')}
67 ${_('never')}
68 %else:
68 %else:
69 ${h.age_component(h.time_to_datetime(c.gist.gist_expires))}
69 ${h.age_component(h.time_to_utcdatetime(c.gist.gist_expires))}
70 %endif
70 %endif
71 </span>
71 </span>
72 </div>
72 </div>
@@ -42,9 +42,9 b''
42 ${_('expires')}: ${_('never')}
42 ${_('expires')}: ${_('never')}
43 %else:
43 %else:
44 %if auth_token.expired:
44 %if auth_token.expired:
45 ${_('expired')}: ${h.age_component(h.time_to_datetime(auth_token.expires))}
45 ${_('expired')}: ${h.age_component(h.time_to_utcdatetime(auth_token.expires))}
46 %else:
46 %else:
47 ${_('expires')}: ${h.age_component(h.time_to_datetime(auth_token.expires))}
47 ${_('expires')}: ${h.age_component(h.time_to_utcdatetime(auth_token.expires))}
48 %endif
48 %endif
49 %endif
49 %endif
50 </td>
50 </td>
@@ -38,9 +38,9 b''
38 ${_('expires')}: ${_('never')}
38 ${_('expires')}: ${_('never')}
39 %else:
39 %else:
40 %if auth_token.expired:
40 %if auth_token.expired:
41 ${_('expired')}: ${h.age_component(h.time_to_datetime(auth_token.expires))}
41 ${_('expired')}: ${h.age_component(h.time_to_utcdatetime(auth_token.expires))}
42 %else:
42 %else:
43 ${_('expires')}: ${h.age_component(h.time_to_datetime(auth_token.expires))}
43 ${_('expires')}: ${h.age_component(h.time_to_utcdatetime(auth_token.expires))}
44 %endif
44 %endif
45 %endif
45 %endif
46 </td>
46 </td>
@@ -12,7 +12,7 b''
12 ${base.gravatar_with_user(comment.author.email, 16)}
12 ${base.gravatar_with_user(comment.author.email, 16)}
13 </div>
13 </div>
14 <div class="date">
14 <div class="date">
15 ${h.age_component(comment.modified_at)}
15 ${h.age_component(comment.modified_at, time_is_local=True)}
16 </div>
16 </div>
17 <div class="status-change">
17 <div class="status-change">
18 %if comment.pull_request:
18 %if comment.pull_request:
@@ -80,7 +80,7 b''
80 ${base.gravatar_with_user(comment.author.email, 16)}
80 ${base.gravatar_with_user(comment.author.email, 16)}
81 </div>
81 </div>
82 <div class="date">
82 <div class="date">
83 ${h.age_component(comment.modified_at)}
83 ${h.age_component(comment.modified_at, time_is_local=True)}
84 </div>
84 </div>
85 %if comment.status_change:
85 %if comment.status_change:
86 <span class="changeset-status-container">
86 <span class="changeset-status-container">
@@ -243,7 +243,7 b''
243
243
244 <%def name="gist_created(created_on)">
244 <%def name="gist_created(created_on)">
245 <div class="created">
245 <div class="created">
246 ${h.age_component(created_on)}
246 ${h.age_component(created_on, time_is_local=True)}
247 </div>
247 </div>
248 </%def>
248 </%def>
249
249
@@ -252,7 +252,7 b''
252 %if expires == -1:
252 %if expires == -1:
253 ${_('never')}
253 ${_('never')}
254 %else:
254 %else:
255 ${h.age_component(h.time_to_datetime(expires))}
255 ${h.age_component(h.time_to_utcdatetime(expires))}
256 %endif
256 %endif
257 </div>
257 </div>
258 </%def>
258 </%def>
@@ -289,7 +289,7 b''
289 </%def>
289 </%def>
290
290
291 <%def name="pullrequest_updated_on(updated_on)">
291 <%def name="pullrequest_updated_on(updated_on)">
292 ${h.age_component(h.time_to_datetime(updated_on))}
292 ${h.age_component(h.time_to_utcdatetime(updated_on))}
293 </%def>
293 </%def>
294
294
295 <%def name="pullrequest_author(full_contact)">
295 <%def name="pullrequest_author(full_contact)">
@@ -11,7 +11,7 b''
11 ${base.gravatar_with_user(f.user.email, 16)}
11 ${base.gravatar_with_user(f.user.email, 16)}
12 </td>
12 </td>
13 <td class="td-time follower_date">
13 <td class="td-time follower_date">
14 ${h.age_component(f.follows_from)}
14 ${h.age_component(f.follows_from, time_is_local=True)}
15 </td>
15 </td>
16 </tr>
16 </tr>
17 % endfor
17 % endfor
@@ -22,7 +22,7 b''
22 <div class="truncate">${f.description}</div>
22 <div class="truncate">${f.description}</div>
23 </td>
23 </td>
24 <td class="td-time follower_date">
24 <td class="td-time follower_date">
25 ${h.age_component(f.created_on)}
25 ${h.age_component(f.created_on, time_is_local=True)}
26 </td>
26 </td>
27 <td class="td-compare">
27 <td class="td-compare">
28 <a title="${_('Compare fork with %s' % c.repo_name)}"
28 <a title="${_('Compare fork with %s' % c.repo_name)}"
@@ -28,7 +28,7 b''
28 </div>
28 </div>
29 <div class="journal_action_params">${h.literal(h.action_parser(entry)[1]())}</div>
29 <div class="journal_action_params">${h.literal(h.action_parser(entry)[1]())}</div>
30 <div class="date">
30 <div class="date">
31 ${h.age_component(entry.action_date)}
31 ${h.age_component(entry.action_date, time_is_local=True)}
32 </div>
32 </div>
33 %endfor
33 %endfor
34 </div>
34 </div>
@@ -46,7 +46,7 b''
46 %endif
46 %endif
47 </td>
47 </td>
48 <td class="td-time">
48 <td class="td-time">
49 ${h.age_component(h.time_to_datetime(entry['date']))}
49 ${h.age_component(h.time_to_utcdatetime(entry['date']))}
50 </td>
50 </td>
51
51
52 <td class="td-user author">
52 <td class="td-user author">
General Comments 0
You need to be logged in to leave comments. Login now