git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [Bug] git-log prints wrong unixtime with --date=format:%s

From
Jeff King <peff@peff.net>
Date
May 18, 2016, 17:49 UTC
Message-ID
<20160518174919.GA5796@sigill.intra.peff.net>
In-Reply-To
<xmqqvb2bs5f5.fsf@gitster.mtv.corp.google.com>
On Wed, May 18, 2016 at 09:21:34AM -0700, Junio C Hamano wrote:
Show 8 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > I tried a few obvious things, but couldn't make anything work. Setting
> > "timezone" manually seems to do nothing. It's supposed to be set by
> > putting the right thing in $TZ and then calling tzset(). So I tried
> > munging $TZ to something like "+0200". It did have _some_ effect, but I
> 
> Wouldn't that be more like "UTC+0200"?

Maybe. I tried several different things, and couldn't make it work sensibly with any of them. My test case is basically:

  git log --format="%ad%n%at" --date=format:'%H:%M %z (%Z)%n%s'

Which should give three lines: the human-readable time and date, strftime's epoch time, and git's epoch time. And the following conditions should be met:

  1. The human-readable time is in the author's timezone (or the user's
     if you use format-local).
  2. The zone offset and name in the first line matches the time we
     show.
  3. The epoch times for the latter lines should match.

We currently get (1) right (which is good, because it is IMHO the most important). I haven't been able to get (2) to change at all, no matter what I do. And (3) is the subject of debate here; I suspect I could make it work at the cost of breaking (1) by giving a "struct tm" that is in UTC.

> In any case, I do not think anybody wants to do tzset() on each and
> every commit while running "git log".  Can we declare "format:<strftime>"
> will always use the local timezone, or something?

I think that is basically the case already. It is in the author's timezone or in the viewing user's timezone (as reported by localtime()), and everything seems to work except the %z zone information and the %s format.

For a raw "%s" date-format, my suggestion is: don't. It is redundant with --date=raw.

I'd love to make %z work, but I have no idea how.
So I guess we could list those in BUGS in one of the manpages.
-Peff
Previous: Jeff KingNext: Michael Heerdegen
Message 8 of 12 in “[Bug] git-log prints wrong unixtime with --date=format:%s”
  1. Michael HeerdegenMay 16, 2016
  2. Michael HeerdegenMay 17, 2016
  3. Jeff KingMay 18, 2016
  4. Jeff KingMay 18, 2016
  5. Junio C HamanoMay 18, 2016
  6. Randall S. BeckerMay 18, 2016
  7. Jeff KingMay 18, 2016
  8. Jeff KingMay 18, 2016
  9. Michael HeerdegenMay 18, 2016
  10. Jeff KingMay 19, 2016
  11. Michael HeerdegenMay 19, 2016
  12. Michael HeerdegenMay 18, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.