diff options
author | Jeff King <peff@peff.net> | 2017-06-15 09:52:17 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-06-15 14:39:15 -0700 |
commit | 6eced3ec5e5d7fbe61de2791e2627b1acf1246b3 (patch) | |
tree | 3c17f3aae308909ff261508ad6e3cbb4f58ec785 /builtin/ls-tree.c | |
parent | t0006: check --date=format zone offsets (diff) | |
download | tgif-6eced3ec5e5d7fbe61de2791e2627b1acf1246b3.tar.xz |
date: use localtime() for "-local" time formats
When we convert seconds-since-epochs timestamps into a
broken-down "struct tm", we do so by adjusting the timestamp
according to the known offset and then using gmtime() to
break down the result. This means that the resulting struct
"knows" that it's in GMT, even though the time it represents
is adjusted for a different zone. The fields where it stores
this data are not portably accessible, so we have no way to
override them to tell them the real zone info.
For the most part, this works. Our date-formatting routines
don't pay attention to these inaccessible fields, and use
the same tz info we provided for adjustment. The one
exception is when we call strftime(), whose %Z format
reveals this hidden timezone data.
We solved that by always showing the empty string for %Z.
This is allowed by POSIX, but not very helpful to the user.
We can't make this work in the general case, as there's no
portable function for setting an arbitrary timezone (and
anyway, we don't have the zone name for the author zones,
only their offsets).
But for the special case of the "-local" formats, we can
just skip the adjustment and use localtime() instead of
gmtime(). This makes --date=format-local:%Z work correctly,
showing the local timezone instead of an empty string.
The new test checks the result for "UTC", our default
test-lib value for $TZ. Using something like EST5 might be
more interesting, but the actual zone string is
system-dependent (for instance, on my system it expands to
just EST). Hopefully "UTC" is vanilla enough that every
system treats it the same.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/ls-tree.c')
0 files changed, 0 insertions, 0 deletions