How to format UTC revision date

Yuya Nishihara yuya at tcha.org
Sun May 3 05:05:51 UTC 2015


On Sun, 03 May 2015 13:23:11 +1000, Lawrence Stewart wrote:
> I want to do this:
> 
> > hg log -r . --template "{date(date,'%Y%m%d%H%M%S')}\n"
> 20150503030535
> 
> but want to apply the format to the revision's date in UTC rather than
> timezone in which the commit was made, and I can't nut out if there's a
> way to do it with templates. I found a hacky way which does work:
> 
> > date -ur `hg log -r . --template '{date(date, "%s")}\n'` '+%Y%m%d%H%M%S'
> 20150502170535

TZ environment variable did the trick:

  % TZ=UTC hg log -r. -T "{date(date|localdate,'%Y%m%d%H%M%S')}\n"

> The templates-only ideas I tried playing around with failed, I guess
> because the inbuilt date() doesn't know how to ingest already formatted
> date strings  e.g.:
> 
> > hg log -r . --template "{date(utcdate(date),'%Y%m%d%H%M%S')}\n"
> ** unknown exception encountered, please report by visiting
> ** http://mercurial.selenic.com/wiki/BugTracker
> ** Python 2.7.9 (default, Mar 11 2015, 01:53:48) [GCC 4.2.1 Compatible
> FreeBSD Clang 3.5.1 (tags/RELEASE_351/final 225668)]
> ** Mercurial Distributed SCM (version 3.3.2)
> ** Extensions loaded: keyword, rebase, histedit, record, strip, mq,
> convert, patchbomb, share
> Traceback (most recent call last):
[...]
>   File "/usr/local/lib/python2.7/site-packages/mercurial/templater.py",
> line 224, in date
>     return util.datestr(date, fmt)
>   File "/usr/local/lib/python2.7/site-packages/mercurial/util.py", line
> 1264, in datestr
>     t, tz = date or makedate()
> ValueError: too many values to unpack

It looks like a bug. Maybe date() have to catch ValueError.

FWIW, your utcdate() function should return (time, offset) tuple. My idea is
to add "{utcoffset(date, offset=0)}" function.

Regards,



More information about the Mercurial mailing list