How to format UTC revision date
Christian Ebert
blacktrash at gmx.net
Mon May 4 00:11:03 UTC 2015
* Yuya Nishihara on Sunday, May 03, 2015 at 14:05:51 +0900
> 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,
With keyword loaded, or
hg --config extensions.keyword= log -r . --template '{date|utcdate}\n'
But it's not exactly the format Lawrence wants.
>> 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.
http://selenic.com/hg/file/e9edd53770fb/hgext/keyword.py#l117
--
Die Wolke Wolfgang
Eine Kindergeschichte mit Bildern. Von Michael Weber.
Das Buch -->> http://www.blacktrash.org/baustellen#wolkewolfgang
Online -->> http://www.blacktrash.org/wolkewolfgang
More information about the Mercurial
mailing list