# HG changeset patch # User Yuya Nishihara # Date 2015-09-01 10:15:16 # Node ID 7012be5ab5bd2d433cd20a29b162dfb60f2e8252 # Parent 7b625baed9954391c201e3ad0b6a40f0e2de80e3 templater: port localdate filter to a function It will be extended to accept a timezone argument. diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -235,10 +235,6 @@ def jsonescape(s): s = s.replace(k, v) return ''.join(_uescape(c) for c in s) -def localdate(text): - """:localdate: Date. Converts a date to local date.""" - return (util.parsedate(text)[0], util.makedate()[1]) - def lower(text): """:lower: Any text. Converts the text to lowercase.""" return encoding.lower(text) @@ -403,7 +399,6 @@ filters = { "isodatesec": isodatesec, "json": json, "jsonescape": jsonescape, - "localdate": localdate, "lower": lower, "nonempty": nonempty, "obfuscate": obfuscate, diff --git a/mercurial/templater.py b/mercurial/templater.py --- a/mercurial/templater.py +++ b/mercurial/templater.py @@ -516,6 +516,21 @@ def label(context, mapping, args): # ignore args[0] (the label string) since this is supposed to be a a no-op yield args[1][0](context, mapping, args[1][1]) +def localdate(context, mapping, args): + """:localdate(date): Converts a date to local date.""" + if len(args) != 1: + # i18n: "localdate" is a keyword + raise error.ParseError(_("localdate expects one argument")) + + date = evalfuncarg(context, mapping, args[0]) + try: + date = util.parsedate(date) + except AttributeError: # not str nor date tuple + # i18n: "localdate" is a keyword + raise error.ParseError(_("localdate expects a date information")) + tzoffset = util.makedate()[1] + return (date[0], tzoffset) + def revset(context, mapping, args): """:revset(query[, formatargs...]): Execute a revision set query. See :hg:`help revset`.""" @@ -700,6 +715,7 @@ funcs = { "indent": indent, "join": join, "label": label, + "localdate": localdate, "pad": pad, "revset": revset, "rstdoc": rstdoc, diff --git a/tests/test-command-template.t b/tests/test-command-template.t --- a/tests/test-command-template.t +++ b/tests/test-command-template.t @@ -2495,6 +2495,10 @@ Behind the scenes, this will throw Attri abort: template filter 'escape' is not compatible with keyword 'date' [255] + $ hg log -l 3 --template 'line: {extras|localdate}\n' + hg: parse error: localdate expects a date information + [255] + Behind the scenes, this will throw ValueError $ hg tip --template '{author|email|date}\n'