comparison mercurial/templatefilters.py @ 13666:c49cddce0a81

templates: provide granularity for future values for age filter
author timeless <timeless@gmail.com>
date Wed, 16 Mar 2011 03:28:56 +0100
parents cc4721ed7a2a
children 7a6a8a069aac
comparison
equal deleted inserted replaced
13665:e798e430c5e5 13666:c49cddce0a81
34 def fmt(t, c): 34 def fmt(t, c):
35 return "%d %s" % (c, plural(t, c)) 35 return "%d %s" % (c, plural(t, c))
36 36
37 now = time.time() 37 now = time.time()
38 then = date[0] 38 then = date[0]
39 future = False
39 if then > now: 40 if then > now:
40 return 'in the future' 41 future = True
41 42 delta = max(1, int(then - now))
42 delta = max(1, int(now - then)) 43 if delta > agescales[0][1] * 30:
43 if delta > agescales[0][1] * 2: 44 return 'in the distant future'
44 return util.shortdate(date) 45 else:
46 delta = max(1, int(now - then))
47 if delta > agescales[0][1] * 2:
48 return util.shortdate(date)
45 49
46 for t, s in agescales: 50 for t, s in agescales:
47 n = delta // s 51 n = delta // s
48 if n >= 2 or s == 1: 52 if n >= 2 or s == 1:
53 if future:
54 return '%s from now' % fmt(t, n)
49 return '%s ago' % fmt(t, n) 55 return '%s ago' % fmt(t, n)
50 56
51 def basename(path): 57 def basename(path):
52 """:basename: Any text. Treats the text as a path, and returns the last 58 """:basename: Any text. Treats the text as a path, and returns the last
53 component of the path after splitting by the path separator 59 component of the path after splitting by the path separator