changeset 17639:d42cc3c880b6

templatefilters: add parameterized date method
author Matt Mackall <mpm@selenic.com>
date Mon, 24 Sep 2012 15:54:45 -0500
parents e2711975be00
children 2d750e885512
files mercurial/templatefilters.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatefilters.py	Mon Sep 24 15:54:44 2012 -0500
+++ b/mercurial/templatefilters.py	Mon Sep 24 15:54:45 2012 -0500
@@ -405,9 +405,19 @@
 
     return fill(text, width)
 
+def datefunc(context, mapping, args):
+    if not (1 <= len(args) <= 2):
+        raise error.ParseError(_("date expects one or two arguments"))
+
+    date = args[0][0](context, mapping, args[0][1])
+    if len(args) == 2:
+        fmt = stringify(args[1][0](context, mapping, args[1][1]))
+        return util.datestr(date, fmt)
+    return util.datestr(date)
 
 funcs = {
     "fill": fillfunc,
+    "date": datefunc,
 }
 
 # tell hggettext to extract docstrings from these functions: