[PATCH 2 of 2] templating: add optional 'ago' parameter to age() function

Andrei Polushin polushin at gmail.com
Sun Dec 18 17:58:27 CST 2011


# HG changeset patch
# User Andrei Polushin <polushin at gmail.com>
# Date 1324251991 -25200
# Node ID 0d4f2f6db72740304931e41f0269e2c4fc9996c8
# Parent  4c2fc9ea89079ea2ad53334fcd13b649f5b14ba7
templating: add optional 'ago' parameter to age() function

This makes it possible to reuse age() function from the environments where the
word 'ago' is redundant, e.g. from TortoiseHg.

diff -r 4c2fc9ea8907 -r 0d4f2f6db727 mercurial/templatefilters.py
--- a/mercurial/templatefilters.py	Mon Dec 19 06:31:14 2011 +0700
+++ b/mercurial/templatefilters.py	Mon Dec 19 06:46:31 2011 +0700
@@ -23,7 +23,7 @@
              ("minute", 60),
              ("second", 1)]
 
-def age(date):
+def age(date, ago = True):
     """:age: Date. Returns a human-readable date/time difference between the
     given date/time and the current date/time.
     """
@@ -51,9 +51,13 @@
     for t, s in agescales:
         n = delta // s
         if n >= 1 or s == 1:
+            formatted = fmt(t, n)
             if future:
-                return '%s from now' % fmt(t, n)
-            return '%s ago' % fmt(t, n)
+                return '%s from now' % formatted
+            elif ago:
+                return '%s ago' % formatted
+            else:
+                return formatted
 
 def basename(path):
     """:basename: Any text. Treats the text as a path, and returns the last


More information about the Mercurial-devel mailing list