how to get UTC timestamp for commit?
Matt Mackall
mpm at selenic.com
Mon Aug 17 19:03:33 UTC 2015
On Mon, 2015-08-17 at 10:18 +0200, Olaf Hering wrote:
> Assume this output:
>
> # mutt-hg $ hg log | head -n 4
> # changeset: 6479:55ea6e829b46
> # tag: tip
> # user: Kevin McCarthy <kevin at 8t8.us>
> # date: Tue Aug 11 11:20:15 2015 -0700
>
> I want to get the UTC date of this commit, like:
>
> # mutt-hg $ hg tip --template "{date(date, '%Y%m%dT%H%M%S')}.r{rev}\n"
> # 20150811T112015.r6479
>
> But it is reported as localtime.
It's not reported in localtime (your localtime is apparently +0200).
It's reported in the timezone of the committer (like email).
> Looking through "hg help templates" I see a
> reference to "hg help dates":
>
> date(date[, fmt])
> Format a date. See "hg help dates" for formatting strings.
>
> But that does not contain a list of formating strings as output, just various
> formats for input.
Right you are! This actually takes the standard % codes from
strftime(3) / date(1), but that won't help you because the timestamp
being formatted is in the wrong offset to start with.
> What is the format string to report UTC time? I do not have control over how
> hg(1) is invoked. All I can do is to pass options to --template.
Sadly, I don't think you can do it, then.
Mercurial dates are indeed stored in (UTC, offset) pairs, but the
templater always combines in the offset for display. There's a helper
function localdate which changes the offset to your current timezone, so
you can do {date|localdate|date}. If you then invoke hg with TZ=UTC,
you'll get a "local" time that's UTC. There is not at present a utcdate
helper.
--
Mathematics is the supreme nostalgia of our time.
More information about the Mercurial
mailing list