From: Paul Eggert <eggert@cs.ucla.edu>
To: DJ Delorie <dj@redhat.com>
Cc: libc-alpha@sourceware.org, Carlos O'Donell <carlos@redhat.com>
Subject: Re: [swbz 29035] mktime vs non-DST
Date: Thu, 18 Aug 2022 14:57:43 -0700 [thread overview]
Message-ID: <cad84eb9-70c8-0335-6b10-5ada66636dac@cs.ucla.edu> (raw)
In-Reply-To: <xnpmgx5k0w.fsf@greed.delorie.com>
A couple of things about those examples.
First, mktime is not "broken" if it returns a time_t that differs from
the time_t that you passed to localtime before fiddling with localtime's
resulting struct tm by changing its is_dst flag. That's normal and
expected mktime behavior, and many (perhaps most) mktime implementations
do that, and this is illustrated by the New York examples.
Second, and more important, the reason users are complaining is that
they want to answer questions like "What time is it 30 days after time
T?" by calling localtime on T, adding 30 to the resulting tm_mday, and
then calling mktime on the modified struct tm. This process fails in
recent glibc if the modified struct tm happens to have the wrong
tm_isdst flag because DST began or end sometime within the 30-day period.
With this in mind, DJ's Tokyo examples (which is the only place where
Gnulib's behavior disagrees with old glibc) illustrate why the
differences between old glibc and Gnulib (a) largely don't matter, and
(b) when they do matter, Gnulib is better. Here's why:
(a) In Tokyo, adding 30 to tm_mday (or whatever) to a contemporary
timestamp cannot yield a timestamp with the wrong tm_isdst because Tokyo
hasn't observed DST since 1951, so DJ's examples of Tokyo "broken dst"
(which is not really broken) largely don't matter.
(b) In the *extremely* unusual case where someone takes a circa-1951
Tokyo timestamp with tm_isdst=1 and adds 25000 to tm_mday to get a
contemporaneous timestamp, Gnulib mktime will treat this consistently
with how it treats New York (and with how it treats adding only 365 to
Tokyo tm_mday), whereas old glibc will treat it inconsistently.
Of course this use case is implausible, but the use case of adding 10
years to a circa-2021 timestamp in Fiji is more plausible, and there
again old glibc is inconsistent whereas Gnulib is consistent.
next prev parent reply other threads:[~2022-08-18 21:58 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-17 21:18 DJ Delorie
2022-08-17 21:50 ` Carlos O'Donell
2022-08-17 23:10 ` Paul Eggert
2022-08-18 1:39 ` DJ Delorie
2022-08-18 2:37 ` Carlos O'Donell
2022-08-18 3:16 ` Paul Eggert
2022-08-18 4:05 ` Carlos O'Donell
2022-08-18 21:17 ` DJ Delorie
2022-08-18 21:57 ` Paul Eggert [this message]
2022-08-18 22:40 ` DJ Delorie
2022-08-18 22:58 ` Paul Eggert
2022-08-19 18:15 ` DJ Delorie
2022-08-19 22:04 ` Paul Eggert
2022-08-18 3:02 ` Paul Eggert
2022-09-08 20:25 ` DJ Delorie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cad84eb9-70c8-0335-6b10-5ada66636dac@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=carlos@redhat.com \
--cc=dj@redhat.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).