changeset 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 e798e430c5e5
children 8cbb59124e67
files mercurial/templatefilters.py tests/test-command-template.t
diffstat 2 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatefilters.py	Wed Mar 16 23:09:14 2011 +0100
+++ b/mercurial/templatefilters.py	Wed Mar 16 03:28:56 2011 +0100
@@ -36,16 +36,22 @@
 
     now = time.time()
     then = date[0]
+    future = False
     if then > now:
-        return 'in the future'
-
-    delta = max(1, int(now - then))
-    if delta > agescales[0][1] * 2:
-        return util.shortdate(date)
+        future = True
+        delta = max(1, int(then - now))
+        if delta > agescales[0][1] * 30:
+            return 'in the distant future'
+    else:
+        delta = max(1, int(now - then))
+        if delta > agescales[0][1] * 2:
+            return util.shortdate(date)
 
     for t, s in agescales:
         n = delta // s
         if n >= 2 or s == 1:
+            if future:
+                return '%s from now' % fmt(t, n)
             return '%s ago' % fmt(t, n)
 
 def basename(path):
--- a/tests/test-command-template.t	Wed Mar 16 23:09:14 2011 +0100
+++ b/tests/test-command-template.t	Wed Mar 16 03:28:56 2011 +0100
@@ -1115,7 +1115,7 @@
   $ hg log --template '{date|age}\n' > /dev/null || exit 1
 
   $ hg log -l1 --template '{date|age}\n' 
-  in the future
+  8 years from now
   $ hg log --template '{date|date}\n'
   Wed Jan 01 10:01:00 2020 +0000
   Mon Jan 12 13:46:40 1970 +0000