# HG changeset patch # User Matt Mackall # Date 2012-09-24 20:54:45 # Node ID d42cc3c880b69d0ba769082dc28fd642568df7e1 # Parent e2711975be00710517f0d41635140015300b3ebb templatefilters: add parameterized date method diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -405,9 +405,19 @@ def fillfunc(context, mapping, args): 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: