mercurial/templater.py
changeset 26128 51f6940d3b4f
parent 26127 7012be5ab5bd
child 26188 662ea52d5dca
equal deleted inserted replaced
26127:7012be5ab5bd 26128:51f6940d3b4f
   515 
   515 
   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):
   519 def localdate(context, mapping, args):
   520     """:localdate(date): Converts a date to local date."""
   520     """:localdate(date[, tz]): Converts a date to the specified timezone.
   521     if len(args) != 1:
   521     The default is local date."""
       
   522     if not (1 <= len(args) <= 2):
   522         # i18n: "localdate" is a keyword
   523         # i18n: "localdate" is a keyword
   523         raise error.ParseError(_("localdate expects one argument"))
   524         raise error.ParseError(_("localdate expects one or two arguments"))
   524 
   525 
   525     date = evalfuncarg(context, mapping, args[0])
   526     date = evalfuncarg(context, mapping, args[0])
   526     try:
   527     try:
   527         date = util.parsedate(date)
   528         date = util.parsedate(date)
   528     except AttributeError:  # not str nor date tuple
   529     except AttributeError:  # not str nor date tuple
   529         # i18n: "localdate" is a keyword
   530         # i18n: "localdate" is a keyword
   530         raise error.ParseError(_("localdate expects a date information"))
   531         raise error.ParseError(_("localdate expects a date information"))
   531     tzoffset = util.makedate()[1]
   532     if len(args) >= 2:
       
   533         tzoffset = None
       
   534         tz = evalfuncarg(context, mapping, args[1])
       
   535         if isinstance(tz, str):
       
   536             tzoffset = util.parsetimezone(tz)
       
   537         if tzoffset is None:
       
   538             try:
       
   539                 tzoffset = int(tz)
       
   540             except (TypeError, ValueError):
       
   541                 # i18n: "localdate" is a keyword
       
   542                 raise error.ParseError(_("localdate expects a timezone"))
       
   543     else:
       
   544         tzoffset = util.makedate()[1]
   532     return (date[0], tzoffset)
   545     return (date[0], tzoffset)
   533 
   546 
   534 def revset(context, mapping, args):
   547 def revset(context, mapping, args):
   535     """:revset(query[, formatargs...]): Execute a revision set query. See
   548     """:revset(query[, formatargs...]): Execute a revision set query. See
   536     :hg:`help revset`."""
   549     :hg:`help revset`."""