templatefilters: add parameterized date method
authorMatt Mackall <mpm@selenic.com>
Mon, 24 Sep 2012 15:54:45 -0500
changeset 17639 d42cc3c880b6
parent 17638 e2711975be00
child 17640 2d750e885512
templatefilters: add parameterized date method
mercurial/templatefilters.py
--- 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: