diff -r 08e042f0a67c -r 67efce231633 mercurial/templateutil.py --- a/mercurial/templateutil.py Sun Mar 18 15:42:28 2018 +0900 +++ b/mercurial/templateutil.py Sun Mar 18 15:55:31 2018 +0900 @@ -16,6 +16,7 @@ util, ) from .utils import ( + dateutil, stringutil, ) @@ -318,6 +319,18 @@ # empty dict/list should be False as they are expected to be '' return bool(stringify(thing)) +def evaldate(context, mapping, arg, err=None): + """Evaluate given argument as a date tuple or a date string; returns + a (unixtime, offset) tuple""" + return unwrapdate(evalrawexp(context, mapping, arg), err) + +def unwrapdate(thing, err=None): + thing = _unwrapvalue(thing) + try: + return dateutil.parsedate(thing) + except AttributeError: + raise error.ParseError(err or _('not a date tuple nor a string')) + def evalinteger(context, mapping, arg, err=None): return unwrapinteger(evalrawexp(context, mapping, arg), err)