Mercurial > public > mercurial-scm > hg
comparison mercurial/templateutil.py @ 37224:67efce231633
templater: factor out function that parses argument as date tuple
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 18 Mar 2018 15:55:31 +0900 |
parents | 54355c243042 |
children | e70a90a72b80 |
comparison
equal
deleted
inserted
replaced
37223:08e042f0a67c | 37224:67efce231633 |
---|---|
14 error, | 14 error, |
15 pycompat, | 15 pycompat, |
16 util, | 16 util, |
17 ) | 17 ) |
18 from .utils import ( | 18 from .utils import ( |
19 dateutil, | |
19 stringutil, | 20 stringutil, |
20 ) | 21 ) |
21 | 22 |
22 class ResourceUnavailable(error.Abort): | 23 class ResourceUnavailable(error.Abort): |
23 pass | 24 pass |
316 return thing | 317 return thing |
317 # other objects are evaluated as strings, which means 0 is True, but | 318 # other objects are evaluated as strings, which means 0 is True, but |
318 # empty dict/list should be False as they are expected to be '' | 319 # empty dict/list should be False as they are expected to be '' |
319 return bool(stringify(thing)) | 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 def evalinteger(context, mapping, arg, err=None): | 334 def evalinteger(context, mapping, arg, err=None): |
322 return unwrapinteger(evalrawexp(context, mapping, arg), err) | 335 return unwrapinteger(evalrawexp(context, mapping, arg), err) |
323 | 336 |
324 def unwrapinteger(thing, err=None): | 337 def unwrapinteger(thing, err=None): |
325 thing = _unwrapvalue(thing) | 338 thing = _unwrapvalue(thing) |