##// END OF EJS Templates
templater: factor out function that parses argument as date tuple
Yuya Nishihara -
r37241:67efce23 default
parent child Browse files
Show More
@@ -34,6 +34,7 b' from .utils import ('
34 34 evalrawexp = templateutil.evalrawexp
35 35 evalfuncarg = templateutil.evalfuncarg
36 36 evalboolean = templateutil.evalboolean
37 evaldate = templateutil.evaldate
37 38 evalinteger = templateutil.evalinteger
38 39 evalstring = templateutil.evalstring
39 40 evalstringliteral = templateutil.evalstringliteral
@@ -373,12 +374,9 b' def localdate(context, mapping, args):'
373 374 # i18n: "localdate" is a keyword
374 375 raise error.ParseError(_("localdate expects one or two arguments"))
375 376
376 date = evalfuncarg(context, mapping, args[0])
377 try:
378 date = dateutil.parsedate(date)
379 except AttributeError: # not str nor date tuple
380 # i18n: "localdate" is a keyword
381 raise error.ParseError(_("localdate expects a date information"))
377 date = evaldate(context, mapping, args[0],
378 # i18n: "localdate" is a keyword
379 _("localdate expects a date information"))
382 380 if len(args) >= 2:
383 381 tzoffset = None
384 382 tz = evalfuncarg(context, mapping, args[1])
@@ -16,6 +16,7 b' from . import ('
16 16 util,
17 17 )
18 18 from .utils import (
19 dateutil,
19 20 stringutil,
20 21 )
21 22
@@ -318,6 +319,18 b' def evalboolean(context, mapping, arg):'
318 319 # empty dict/list should be False as they are expected to be ''
319 320 return bool(stringify(thing))
320 321
322 def evaldate(context, mapping, arg, err=None):
323 """Evaluate given argument as a date tuple or a date string; returns
324 a (unixtime, offset) tuple"""
325 return unwrapdate(evalrawexp(context, mapping, arg), err)
326
327 def unwrapdate(thing, err=None):
328 thing = _unwrapvalue(thing)
329 try:
330 return dateutil.parsedate(thing)
331 except AttributeError:
332 raise error.ParseError(err or _('not a date tuple nor a string'))
333
321 334 def evalinteger(context, mapping, arg, err=None):
322 335 return unwrapinteger(evalrawexp(context, mapping, arg), err)
323 336
General Comments 0
You need to be logged in to leave comments. Login now