* Timezone with DATE_STRFTIME
@ 2016-02-08 14:33 John Keeping
2016-02-08 15:28 ` Jeff King
0 siblings, 1 reply; 4+ messages in thread
From: John Keeping @ 2016-02-08 14:33 UTC (permalink / raw)
To: git, Jeff King
I have just noticed that with DATE_STRFTIME, the timezone in the output
is likely to be incorrect.
For all other time formats, we print the string ourselves and use the
correct timezone from the input, but with DATE_STRFTIME strftime(3) will
always use the system timezone.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Timezone with DATE_STRFTIME
2016-02-08 14:33 Timezone with DATE_STRFTIME John Keeping
@ 2016-02-08 15:28 ` Jeff King
2016-02-08 15:44 ` Jeff King
2016-02-08 15:46 ` John Keeping
0 siblings, 2 replies; 4+ messages in thread
From: Jeff King @ 2016-02-08 15:28 UTC (permalink / raw)
To: John Keeping; +Cc: git
On Mon, Feb 08, 2016 at 02:33:17PM +0000, John Keeping wrote:
> I have just noticed that with DATE_STRFTIME, the timezone in the output
> is likely to be incorrect.
>
> For all other time formats, we print the string ourselves and use the
> correct timezone from the input, but with DATE_STRFTIME strftime(3) will
> always use the system timezone.
You mean here that the "%z" formatting will not be correct, right?
AFAICT the time shown is generally correct for the original of the
author, and we simply need to communicate the zone to strftime.
Taking the current tip of master, for instance, I get:
$ for i in \
default \
local \
"format:%H:%M %z" \
"format-local:%H:%M %z"; do
git log -1 --format=%ad --date="$i" ff4ea6004
done
Fri Feb 5 15:24:02 2016 -0800
Fri Feb 5 18:24:02 2016
15:24 +0000
18:24 +0000
You can see that my system is in -0500, three hours ahead of the author.
And as expected, strftime shows the time in the original author's
timezone. The %z information is totally bogus, but I don't think it has
anything to do with the system time. It is simply that we don't provide
it (...but having just looked at _your_ local timezone from your email,
I can guess how you got confused :) ).
So I think the fix is probably just that we need to feed the zone
information to strftime via the "struct tm".
-Peff
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Timezone with DATE_STRFTIME
2016-02-08 15:28 ` Jeff King
@ 2016-02-08 15:44 ` Jeff King
2016-02-08 15:46 ` John Keeping
1 sibling, 0 replies; 4+ messages in thread
From: Jeff King @ 2016-02-08 15:44 UTC (permalink / raw)
To: John Keeping; +Cc: git
On Mon, Feb 08, 2016 at 10:28:58AM -0500, Jeff King wrote:
> So I think the fix is probably just that we need to feed the zone
> information to strftime via the "struct tm".
Ugh, I forgot how horrible the strftime interface is.
There is no zone information in "struct tm". It gets pulled from the
magic global variable "timezone", and you're supposed to use "tzset" to
set it up. We don't. POSIX says:
Local timezone information is used as though strftime() called
tzset().
but on my system that does not seem to be the case. At any rate, our
options are:
1. Trying to munge a global variable with the timezone information we
have just for the duration of our strftime call.
or
2. Admit that strftime's "%z" is crap, and tell people not to use it.
I think I am leaning towards the latter, though unfortunately I don't
think there is a way to find out the author's timezone via
--date=format, then. Perhaps it should default to "--date=format-local:".
-Peff
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Timezone with DATE_STRFTIME
2016-02-08 15:28 ` Jeff King
2016-02-08 15:44 ` Jeff King
@ 2016-02-08 15:46 ` John Keeping
1 sibling, 0 replies; 4+ messages in thread
From: John Keeping @ 2016-02-08 15:46 UTC (permalink / raw)
To: Jeff King; +Cc: git
On Mon, Feb 08, 2016 at 10:28:58AM -0500, Jeff King wrote:
> On Mon, Feb 08, 2016 at 02:33:17PM +0000, John Keeping wrote:
>
> > I have just noticed that with DATE_STRFTIME, the timezone in the output
> > is likely to be incorrect.
> >
> > For all other time formats, we print the string ourselves and use the
> > correct timezone from the input, but with DATE_STRFTIME strftime(3) will
> > always use the system timezone.
>
> You mean here that the "%z" formatting will not be correct, right?
> AFAICT the time shown is generally correct for the original of the
> author, and we simply need to communicate the zone to strftime.
>
> Taking the current tip of master, for instance, I get:
>
> $ for i in \
> default \
> local \
> "format:%H:%M %z" \
> "format-local:%H:%M %z"; do
> git log -1 --format=%ad --date="$i" ff4ea6004
> done
> Fri Feb 5 15:24:02 2016 -0800
> Fri Feb 5 18:24:02 2016
> 15:24 +0000
> 18:24 +0000
>
> You can see that my system is in -0500, three hours ahead of the author.
> And as expected, strftime shows the time in the original author's
> timezone. The %z information is totally bogus, but I don't think it has
> anything to do with the system time. It is simply that we don't provide
> it (...but having just looked at _your_ local timezone from your email,
> I can guess how you got confused :) ).
>
> So I think the fix is probably just that we need to feed the zone
> information to strftime via the "struct tm".
If "struct tm" had a standard field for that...
Obviously "struct tm" does have a field for the offset (which is how we
end up in +0000 above, because our "struct tm" comes from gmtime(3)),
but it's not standardized so I don't think we can rely on it.
AFAICT the only way to pass the timezone into the C library time
functions is via $TZ or the global "timezone" variable, but from looking
at a couple of implementations I don't think strftime() will actually
look at those (the timezone is instead embedded when the "struct tm" is
generated).
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-02-08 15:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-08 14:33 Timezone with DATE_STRFTIME John Keeping
2016-02-08 15:28 ` Jeff King
2016-02-08 15:44 ` Jeff King
2016-02-08 15:46 ` John Keeping
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).