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

Re: git-2.13.0: log --date=format:%z not working

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
May 28, 2017, 10:29 UTC
Message-ID
<CACBZZX6zG0z90coXz_Xzqvdp+9LpJ4RE2dAJggfLL-nd0nkWVQ@mail.gmail.com>
In-Reply-To
<20170527214611.suohggo226tvmbgt@sigill.intra.peff.net>
On Sat, May 27, 2017 at 11:46 PM, Jeff King <peff@peff.net> wrote:
Show 41 quoted lines
> On Sat, May 27, 2017 at 06:57:08PM +0200, Ævar Arnfjörð Bjarmason wrote:
>
>> There's another test which breaks if we just s/gmtime/localtime/g. As
>> far as I can tell to make the non-local case work we'd need to do a
>> whole dance where we set the TZ variable to e.g. UTC$offset, then call
>> strftime(), then call it again. Maybe there's some way to just specify
>> the tz offset, but I didn't find any in a quick skimming of time.h.
>
> There isn't. At least on _some_ platforms, the zone information is
> embedded in "struct tm" and stored by gmtime() and localtime(), but the
> fields aren't publicly accessible. Which is why your patch worked for
> format-local (it swaps out gmtime() for localtime() which sets those
> fields behind the scenes). But:
>
>   - I'm not sure that's guaranteed by the standard; strftime() might get
>     its zone information elsewhere (if it needs to reliably distinguish
>     between gmtime() and localtime() results it has to at least set a
>     bit in the "struct tm", but that bit may not be the full zone info).
>
>   - Even if it does work, you're stuck with only the local timezone. In
>     theory you could temporarily tweak the process's timezone, call
>     localtime(), and then tweak it back. I was never able to get that to
>     work (links below).
>
> On glibc, at least, you can access the zone fields in "struct tm" by
> compiling with _DEFAULT_SOURCE.
>
> So I think the best we could do is probably to have a feature macro like
> TM_HAS_GMTOFF, and set tm->tm_gmtoff and tm->tm_zone on platforms that
> support it. I'm not sure what we'd put in the latter, though; we don't
> actually have the timezone name at all (we just have "+0200" or whatever
> we parsed from the git object, but that would be better than nothing).
>
> That leaves other platforms still broken, but like I said, I don't think
> there's a portable solution.
>
> Here are some links to past explorations:
>
>   http://public-inbox.org/git/20160208152858.GA17226@sigill.intra.peff.net/
>
>   http://public-inbox.org/git/87vb2d37ea.fsf@web.de/

There's a third and possibly least shitty option that isn't covered in those threads; We could just make a pass over the strftime format ourselves and replace %z and %Z with the timezone (as done for DATE_ISO8601_STRICT in date.c), then hand the rest off to strftime().

I'm not going to pursue it though, Ulrich, are you maybe interested in hacking on that?

Previous: Jeff KingNext: Junio C Hamano
Message 4 of 44 in “git-2.13.0: log --date=format:%z not working”
  1. Ulrich MuellerMay 26, 2017
  2. Ævar Arnfjörð BjarmasonMay 27, 2017
  3. Jeff KingMay 27, 2017
  4. Ævar Arnfjörð BjarmasonMay 28, 2017
  5. Junio C HamanoMay 29, 2017
  6. René ScharfeMay 28, 2017
  7. Junio C HamanoJun 2, 2017
  8. Jeff KingJun 2, 2017
  9. René ScharfeJun 2, 2017
  10. Jeff KingJun 2, 2017
  11. Ulrich MuellerJun 2, 2017
  12. Jeff KingJun 2, 2017
  13. Ulrich MuellerJun 2, 2017
  14. Jeff KingJun 2, 2017
  15. strbuf: let strbuf_addftime handle %z and %Z itselfRené Scharfe, Jun 3, 2017
  16. Ulrich MuellerJun 3, 2017
  17. René ScharfeJun 3, 2017
  18. Jeff KingJun 7, 2017
  19. date: use localtime() for "-local" time formatsJeff King, Jun 7, 2017
  20. René ScharfeJun 11, 2017
  21. Junio C HamanoJun 12, 2017
  22. Ævar Arnfjörð BjarmasonJun 12, 2017
  23. Ulrich MuellerJun 12, 2017
  24. Ævar Arnfjörð BjarmasonJun 12, 2017
  25. Junio C HamanoJun 12, 2017
  26. Jeff KingJun 12, 2017
  27. Ævar Arnfjörð BjarmasonJun 12, 2017
  28. Jeff KingJun 12, 2017
  29. Linus TorvaldsJun 13, 2017
  30. René ScharfeJun 12, 2017
  31. Ævar Arnfjörð BjarmasonJun 13, 2017
  32. Ulrich MuellerJun 13, 2017
  33. René ScharfeJun 12, 2017
  34. Jeff KingJun 12, 2017
  35. strbuf: let strbuf_addftime handle %z and %Z itselfRené Scharfe, Jun 15, 2017
  36. Ulrich MuellerJun 15, 2017
  37. René ScharfeJun 15, 2017
  38. strbuf: let strbuf_addftime handle %z and %Z itselfRené Scharfe, Jun 15, 2017
  39. Jeff KingJun 15, 2017
  40. 1/2 t0006: check --date=format zone offsetsJeff King, Jun 15, 2017
  41. 2/2 date: use localtime() for "-local" time formatsJeff King, Jun 15, 2017
  42. René ScharfeJun 15, 2017
  43. Junio C HamanoJun 15, 2017
  44. Jeff KingJun 16, 2017

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.