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

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

From
Michael Heerdegen <michael_heerdegen@web.de>
Date
May 16, 2016, 23:33 UTC
Message-ID
<87vb2d37ea.fsf@web.de>
Hello,
the command
   git log --pretty=format:%ad --date=format:%s

displays wrong unixtime values; apparently how much the printed value differs from the expected value depends on the system's time zone and whether daylight savings time is enabled or not.

Here is a reproducible recipe compiled by Yuri Khan who helped me localizing the problem and whom I CC'd:

0. Versions
    $ git --version
    git version 2.8.2
    $ dpkg -l tzdata | tail -1
    ii  tzdata  2016d-0ubuntu0.16.04 all  time zone and
daylight-saving time data
1. Initialize an empty Git repository:
    $ git init test
    $ cd test
2. Make a commit, using the Europe/Berlin time zone:
    $ TZ=Europe/Berlin git commit -m 'test' --allow-empty
3. Examine the timestamp recorded in the commit object:
    $ git cat-file -p HEAD | grep author
    author Yuri Khan <yurivkhan@gmail.com> 1463260938 +0200
4. Check that it corresponds to the current time:
    $ date +%s
    1463260977
5. Try to get the commit date in the unixtime format:
    $ TZ=Europe/Berlin git log --pretty=format:%ad --date=format:%s -1

Expected result: 1463260938 (same as recorded in the commit object). Observed result: 1463264538 (3600s = one hour ahead).

For lulz, use another time zone:
    $ TZ=Asia/Novosibirsk git log --pretty=format:%ad --date=format:%s -1

Expected result: 1463260938 (unixtime is always UTC and should not depend on TZ). Observed result: 1463246538 (-14400s = 4 hours behind).

Not even specifying the UTC time zone helps:
    $ TZ=UTC git log --pretty=format:%ad --date=format:%s -1

Expected result: still 1463260938. Observed result: 1463268138 (7200s = 2 hours ahead).

FWIW, personally I have not bound the TZ environment variable, my time zone is constantly that of Berlin, currently CEST.

Many thanks in advance,
Michael.
Next: Michael Heerdegen
Message 1 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.