##// END OF EJS Templates
templatefilters: add short format for age formatting...
David Soria Parra -
r19736:f08e542c default
parent child Browse files
Show More
@@ -15,15 +15,15 def addbreaks(text):
15 15 """
16 16 return text.replace('\n', '<br/>\n')
17 17
18 agescales = [("year", 3600 * 24 * 365),
19 ("month", 3600 * 24 * 30),
20 ("week", 3600 * 24 * 7),
21 ("day", 3600 * 24),
22 ("hour", 3600),
23 ("minute", 60),
24 ("second", 1)]
18 agescales = [("year", 3600 * 24 * 365, 'Y'),
19 ("month", 3600 * 24 * 30, 'M'),
20 ("week", 3600 * 24 * 7, 'W'),
21 ("day", 3600 * 24, 'd'),
22 ("hour", 3600, 'h'),
23 ("minute", 60, 'm'),
24 ("second", 1, 's')]
25 25
26 def age(date):
26 def age(date, abbrev=False):
27 27 """:age: Date. Returns a human-readable date/time difference between the
28 28 given date/time and the current date/time.
29 29 """
@@ -32,7 +32,9 def age(date):
32 32 if c == 1:
33 33 return t
34 34 return t + "s"
35 def fmt(t, c):
35 def fmt(t, c, a):
36 if abbrev:
37 return "%d%s" % (c, a)
36 38 return "%d %s" % (c, plural(t, c))
37 39
38 40 now = time.time()
@@ -48,12 +50,12 def age(date):
48 50 if delta > agescales[0][1] * 2:
49 51 return util.shortdate(date)
50 52
51 for t, s in agescales:
53 for t, s, a in agescales:
52 54 n = delta // s
53 55 if n >= 2 or s == 1:
54 56 if future:
55 return '%s from now' % fmt(t, n)
56 return '%s ago' % fmt(t, n)
57 return '%s from now' % fmt(t, n, a)
58 return '%s ago' % fmt(t, n, a)
57 59
58 60 def basename(path):
59 61 """:basename: Any text. Treats the text as a path, and returns the last
General Comments 0
You need to be logged in to leave comments. Login now