##// END OF EJS Templates
templater: port localdate filter to a function...
Yuya Nishihara -
r26127:7012be5a default
parent child Browse files
Show More
@@ -235,10 +235,6 b' def jsonescape(s):'
235 s = s.replace(k, v)
235 s = s.replace(k, v)
236 return ''.join(_uescape(c) for c in s)
236 return ''.join(_uescape(c) for c in s)
237
237
238 def localdate(text):
239 """:localdate: Date. Converts a date to local date."""
240 return (util.parsedate(text)[0], util.makedate()[1])
241
242 def lower(text):
238 def lower(text):
243 """:lower: Any text. Converts the text to lowercase."""
239 """:lower: Any text. Converts the text to lowercase."""
244 return encoding.lower(text)
240 return encoding.lower(text)
@@ -403,7 +399,6 b' filters = {'
403 "isodatesec": isodatesec,
399 "isodatesec": isodatesec,
404 "json": json,
400 "json": json,
405 "jsonescape": jsonescape,
401 "jsonescape": jsonescape,
406 "localdate": localdate,
407 "lower": lower,
402 "lower": lower,
408 "nonempty": nonempty,
403 "nonempty": nonempty,
409 "obfuscate": obfuscate,
404 "obfuscate": obfuscate,
@@ -516,6 +516,21 b' def label(context, mapping, args):'
516 # ignore args[0] (the label string) since this is supposed to be a a no-op
516 # ignore args[0] (the label string) since this is supposed to be a a no-op
517 yield args[1][0](context, mapping, args[1][1])
517 yield args[1][0](context, mapping, args[1][1])
518
518
519 def localdate(context, mapping, args):
520 """:localdate(date): Converts a date to local date."""
521 if len(args) != 1:
522 # i18n: "localdate" is a keyword
523 raise error.ParseError(_("localdate expects one argument"))
524
525 date = evalfuncarg(context, mapping, args[0])
526 try:
527 date = util.parsedate(date)
528 except AttributeError: # not str nor date tuple
529 # i18n: "localdate" is a keyword
530 raise error.ParseError(_("localdate expects a date information"))
531 tzoffset = util.makedate()[1]
532 return (date[0], tzoffset)
533
519 def revset(context, mapping, args):
534 def revset(context, mapping, args):
520 """:revset(query[, formatargs...]): Execute a revision set query. See
535 """:revset(query[, formatargs...]): Execute a revision set query. See
521 :hg:`help revset`."""
536 :hg:`help revset`."""
@@ -700,6 +715,7 b' funcs = {'
700 "indent": indent,
715 "indent": indent,
701 "join": join,
716 "join": join,
702 "label": label,
717 "label": label,
718 "localdate": localdate,
703 "pad": pad,
719 "pad": pad,
704 "revset": revset,
720 "revset": revset,
705 "rstdoc": rstdoc,
721 "rstdoc": rstdoc,
@@ -2495,6 +2495,10 b' Behind the scenes, this will throw Attri'
2495 abort: template filter 'escape' is not compatible with keyword 'date'
2495 abort: template filter 'escape' is not compatible with keyword 'date'
2496 [255]
2496 [255]
2497
2497
2498 $ hg log -l 3 --template 'line: {extras|localdate}\n'
2499 hg: parse error: localdate expects a date information
2500 [255]
2501
2498 Behind the scenes, this will throw ValueError
2502 Behind the scenes, this will throw ValueError
2499
2503
2500 $ hg tip --template '{author|email|date}\n'
2504 $ hg tip --template '{author|email|date}\n'
General Comments 0
You need to be logged in to leave comments. Login now