##// 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 71 from rhodecode.lib.action_parser import action_parser
72 72 from rhodecode.lib.utils import repo_name_slug, get_custom_lexer
73 73 from rhodecode.lib.utils2 import str2bool, safe_unicode, safe_str, \
74 get_commit_safe, datetime_to_time, time_to_datetime, AttributeDict, \
75 safe_int, md5, md5_safe
74 get_commit_safe, datetime_to_time, time_to_datetime, time_to_utcdatetime, \
75 AttributeDict, safe_int, md5, md5_safe
76 76 from rhodecode.lib.markup_renderer import MarkupRenderer
77 77 from rhodecode.lib.vcs.exceptions import CommitDoesNotExistError
78 78 from rhodecode.lib.vcs.backends.base import BaseChangeset, EmptyCommit
@@ -649,13 +649,20 b' short_id = lambda x: x[:12]'
649 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 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 656 if isinstance(datetime_iso, datetime) and not datetime_iso.tzinfo:
657 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 666 return literal(
660 667 '<time class="timeago tooltip" '
661 668 'title="{1}" datetime="{0}{2}">{1}</time>'.format(
@@ -608,6 +608,16 b' def time_to_datetime(tm):'
608 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 621 MENTIONS_REGEX = re.compile(
612 622 # ^@ or @ without any special chars in front
613 623 r'(?:^@|[^a-zA-Z0-9\-\_\.]@)'
@@ -190,7 +190,7 b' var AgeModule = (function () {'
190 190
191 191 },
192 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 66 %if c.gist.gist_expires == -1:
67 67 ${_('never')}
68 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 70 %endif
71 71 </span>
72 72 </div>
@@ -42,9 +42,9 b''
42 42 ${_('expires')}: ${_('never')}
43 43 %else:
44 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 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 48 %endif
49 49 %endif
50 50 </td>
@@ -38,9 +38,9 b''
38 38 ${_('expires')}: ${_('never')}
39 39 %else:
40 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 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 44 %endif
45 45 %endif
46 46 </td>
@@ -12,7 +12,7 b''
12 12 ${base.gravatar_with_user(comment.author.email, 16)}
13 13 </div>
14 14 <div class="date">
15 ${h.age_component(comment.modified_at)}
15 ${h.age_component(comment.modified_at, time_is_local=True)}
16 16 </div>
17 17 <div class="status-change">
18 18 %if comment.pull_request:
@@ -80,7 +80,7 b''
80 80 ${base.gravatar_with_user(comment.author.email, 16)}
81 81 </div>
82 82 <div class="date">
83 ${h.age_component(comment.modified_at)}
83 ${h.age_component(comment.modified_at, time_is_local=True)}
84 84 </div>
85 85 %if comment.status_change:
86 86 <span class="changeset-status-container">
@@ -243,7 +243,7 b''
243 243
244 244 <%def name="gist_created(created_on)">
245 245 <div class="created">
246 ${h.age_component(created_on)}
246 ${h.age_component(created_on, time_is_local=True)}
247 247 </div>
248 248 </%def>
249 249
@@ -252,7 +252,7 b''
252 252 %if expires == -1:
253 253 ${_('never')}
254 254 %else:
255 ${h.age_component(h.time_to_datetime(expires))}
255 ${h.age_component(h.time_to_utcdatetime(expires))}
256 256 %endif
257 257 </div>
258 258 </%def>
@@ -289,7 +289,7 b''
289 289 </%def>
290 290
291 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 293 </%def>
294 294
295 295 <%def name="pullrequest_author(full_contact)">
@@ -11,7 +11,7 b''
11 11 ${base.gravatar_with_user(f.user.email, 16)}
12 12 </td>
13 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 15 </td>
16 16 </tr>
17 17 % endfor
@@ -22,7 +22,7 b''
22 22 <div class="truncate">${f.description}</div>
23 23 </td>
24 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 26 </td>
27 27 <td class="td-compare">
28 28 <a title="${_('Compare fork with %s' % c.repo_name)}"
@@ -28,7 +28,7 b''
28 28 </div>
29 29 <div class="journal_action_params">${h.literal(h.action_parser(entry)[1]())}</div>
30 30 <div class="date">
31 ${h.age_component(entry.action_date)}
31 ${h.age_component(entry.action_date, time_is_local=True)}
32 32 </div>
33 33 %endfor
34 34 </div>
@@ -46,7 +46,7 b''
46 46 %endif
47 47 </td>
48 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 50 </td>
51 51
52 52 <td class="td-user author">
General Comments 0
You need to be logged in to leave comments. Login now