Permalink
Browse files

Add `format` keyword argument to `pretty_dateinfo`.

  • Loading branch information...
1 parent 7304a8c commit 1c5de2ea3541c0affdd7cbc175c1147feccf0744 @jun66j5 committed Mar 2, 2011
@@ -44,7 +44,7 @@ <h1 py:choose="">
<dd class="time" py:choose="">
<em py:when="multi" class="multi">(multiple changes)</em>
<py:when test="change.date">
- <i18n:msg params="date, duration">${format_datetime(change.date)} (${pretty_dateinfo(change.date)})</i18n:msg>
+ <i18n:msg params="date, duration">${format_datetime(change.date)} (${pretty_dateinfo(change.date, format='relative')})</i18n:msg>
</py:when>
<py:otherwise>--</py:otherwise>
</dd>
@@ -25,7 +25,7 @@
<py:choose>
<p py:when="milestone.completed" class="date">
<i18n:msg params="duration, date">
- Completed ${pretty_dateinfo(milestone.completed)} (${format_datetime(milestone.completed)})
+ Completed ${pretty_dateinfo(milestone.completed, format='relative')} (${format_datetime(milestone.completed)})
</i18n:msg>
</p>
<p py:when="milestone.is_late" class="date">
@@ -40,7 +40,7 @@
<py:choose>
<p py:when="milestone.completed" class="date">
<i18n:msg params="duration, date">
- Completed ${pretty_dateinfo(milestone.completed)} (${format_datetime(milestone.completed)})
+ Completed ${pretty_dateinfo(milestone.completed, format='relative')} (${format_datetime(milestone.completed)})
</i18n:msg>
</p>
<p py:when="milestone.is_late" class="date">
@@ -1320,7 +1320,7 @@ def runTest(self):
tc.submit('remove')
tc.go(ticket_url)
tc.find('<strong>Milestone</strong>[ \n\t]*<em>%s</em> deleted' % name)
- tc.find('Changed <a.*</a> ago by admin')
+ tc.find('Changed <a.* ago</a> by admin')
tc.notfind('anonymous')
View
@@ -266,16 +266,13 @@ def pre_process_request(self, req, handler):
def post_process_request(self, req, template, data, content_type):
if data:
- def dateinfo(date):
- return self.get_timeline_link(req, date,
- pretty_timedelta(date),
- precision='second')
- def pretty_dateinfo(date, dateonly=False):
- option = req.session.get('dateinfo') or \
- Chrome(self.env).dateinfo_format
+ def pretty_dateinfo(date, format=None, dateonly=False):
absolute = user_time(req, format_datetime, date)
relative = pretty_timedelta(date)
- if option == 'absolute':
+ if not format:
+ format = req.session.get('dateinfo') or \
+ Chrome(self.env).dateinfo_format
+ if format == 'absolute':
label = absolute
title = _("%(relativetime)s ago in Timeline",
relativetime=relative)
@@ -286,8 +283,10 @@ def pretty_dateinfo(date, dateonly=False):
absolutetime=absolute)
return self.get_timeline_link(req, date, label,
precision='second', title=title)
- data['dateinfo'] = dateinfo
+ def dateinfo(date):
+ return pretty_dateinfo(date, format='relative', dateonly=True)
data['pretty_dateinfo'] = pretty_dateinfo
+ data['dateinfo'] = dateinfo
return template, data, content_type
# IWikiSyntaxProvider methods
View
@@ -422,10 +422,10 @@ class Chrome(Component):
this to 0 to disable automatic preview. The default is 2.0 seconds.
(''since 0.12'')""")
- dateinfo_format = Option('trac', 'dateinfo_format', '',
- """The date information format. Valid options are 'absolute' for
- displaying absolute format, or leave it empty which means the date
- information will be displayed relative format. (''since 0.13'')
+ dateinfo_format = Option('trac', 'dateinfo_format', 'relative',
+ """The date information format. Valid options are 'relative' for
+ displaying relative format and 'absolute' for displaying absolute
+ format. (''since 0.13'')
""")
templates = None
@@ -787,15 +787,12 @@ def populate_data(self, req, data):
exception_to_unicode(e))
show_email_addresses = False
- def dateinfo(date):
- return tag.span(pretty_timedelta(date),
- title=user_time(req, format_datetime, date))
-
- def pretty_dateinfo(date, dateonly=False):
- option = req.session.get('dateinfo') or self.dateinfo_format
+ def pretty_dateinfo(date, format=None, dateonly=False):
absolute = user_time(req, format_datetime, date)
relative = pretty_timedelta(date)
- if option == 'absolute':
+ if not format:
+ format = req.session.get('dateinfo') or self.dateinfo_format
+ if format == 'absolute':
label = absolute
title = _("%(relativetime)s ago", relativetime=relative)
else:
@@ -804,6 +801,9 @@ def pretty_dateinfo(date, dateonly=False):
title = absolute
return tag.span(label, title=title)
+ def dateinfo(date):
+ return pretty_timedelta(date, format='relative', dateonly=True)
+
def get_rel_url(resource, **kwargs):
return get_resource_url(self.env, resource, href, **kwargs)

0 comments on commit 1c5de2e

Please sign in to comment.