Show More
@@ -69,6 +69,10 b' Some sample command line templates:' | |||
|
69 | 69 | |
|
70 | 70 | $ hg log -r 0 --template "{date(date, '%Y')}\n" |
|
71 | 71 | |
|
72 | - Display date in UTC:: | |
|
73 | ||
|
74 | $ hg log -r 0 --template "{localdate(date, 'UTC')|date}\n" | |
|
75 | ||
|
72 | 76 | - Output the description set to a fill-width of 30:: |
|
73 | 77 | |
|
74 | 78 | $ hg log -r 0 --template "{fill(desc, 30)}" |
@@ -517,10 +517,11 b' def label(context, mapping, args):' | |||
|
517 | 517 | yield args[1][0](context, mapping, args[1][1]) |
|
518 | 518 | |
|
519 | 519 | def localdate(context, mapping, args): |
|
520 |
""":localdate(date): Converts a date to |
|
|
521 | if len(args) != 1: | |
|
520 | """:localdate(date[, tz]): Converts a date to the specified timezone. | |
|
521 | The default is local date.""" | |
|
522 | if not (1 <= len(args) <= 2): | |
|
522 | 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 | 526 | date = evalfuncarg(context, mapping, args[0]) |
|
526 | 527 | try: |
@@ -528,7 +529,19 b' def localdate(context, mapping, args):' | |||
|
528 | 529 | except AttributeError: # not str nor date tuple |
|
529 | 530 | # i18n: "localdate" is a keyword |
|
530 | 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 | 545 | return (date[0], tzoffset) |
|
533 | 546 | |
|
534 | 547 | def revset(context, mapping, args): |
@@ -3109,6 +3109,25 b' Test get function:' | |||
|
3109 | 3109 | hg: parse error: get() expects a dict as first argument |
|
3110 | 3110 | [255] |
|
3111 | 3111 | |
|
3112 | Test localdate(date, tz) function: | |
|
3113 | ||
|
3114 | $ TZ=JST-09 hg log -r0 -T '{date|localdate|isodate}\n' | |
|
3115 | 1970-01-01 09:00 +0900 | |
|
3116 | $ TZ=JST-09 hg log -r0 -T '{localdate(date, "UTC")|isodate}\n' | |
|
3117 | 1970-01-01 00:00 +0000 | |
|
3118 | $ TZ=JST-09 hg log -r0 -T '{localdate(date, "+0200")|isodate}\n' | |
|
3119 | 1970-01-01 02:00 +0200 | |
|
3120 | $ TZ=JST-09 hg log -r0 -T '{localdate(date, "0")|isodate}\n' | |
|
3121 | 1970-01-01 00:00 +0000 | |
|
3122 | $ TZ=JST-09 hg log -r0 -T '{localdate(date, 0)|isodate}\n' | |
|
3123 | 1970-01-01 00:00 +0000 | |
|
3124 | $ hg log -r0 -T '{localdate(date, "invalid")|isodate}\n' | |
|
3125 | hg: parse error: localdate expects a timezone | |
|
3126 | [255] | |
|
3127 | $ hg log -r0 -T '{localdate(date, date)|isodate}\n' | |
|
3128 | hg: parse error: localdate expects a timezone | |
|
3129 | [255] | |
|
3130 | ||
|
3112 | 3131 | Test shortest(node) function: |
|
3113 | 3132 | |
|
3114 | 3133 | $ echo b > b |
General Comments 0
You need to be logged in to leave comments.
Login now