Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Apr 2002 16:28:05 -0400 (EDT)
From:      Garrett Wollman <wollman@lcs.mit.edu>
To:        Sean Chittenden <sean@chittenden.org>
Cc:        freebsd-standards@FreeBSD.ORG
Subject:   Re: mktime() doesn't fix deadzones...
Message-ID:  <200204102028.g3AKS5h68482@khavrinen.lcs.mit.edu>
In-Reply-To: <20020410125409.B34587@ninja1.internal>
References:  <sean@chittenden.org> <200204101233.g3ACXaOF052655@hak.lan.Awfulhak.org> <20020410125409.B34587@ninja1.internal>

next in thread | previous in thread | raw e-mail | index | archive | help
<<On Wed, 10 Apr 2002 12:54:09 -0700, Sean Chittenden <sean@chittenden.org> said:

> I like that mktime() returns -1 for invalid times, but I don't think
> Apr 7th @2am-8 is an invalid time.  Not correct, but not invalid
> either.

There is no such time as 2001-04-07T0200 when US DST rules are used.
This time simply does not exist, and mktime() correctly returns an
error.  It has no way of knowing that you ``really meant''
2001-04-07T0300.

The way mktime() works is by performing a binary search on the time_t
space, after normalization.  If it determines that the time you have
requested is not a possible return value of localtime(), then it
returns an error.  (It will also return an error if the time you have
requested is not unique, as happens during the autumn transition
period if tm_isdst is set to -1.)

> Sun Apr 07 02:00:00 PST 2002 =3D 1018173600

...except that PST is not in effect at that time in your timezone.

However, there is a bug here.  Perhaps this is fixed in a more recent
tzcode; someone should check.  The bug has to do with normalization.
Consider the following test program fragment:

        tm.tm_year = 102;
        tm.tm_mon = 3;
        tm.tm_mday = 7;
        tm.tm_hour = 1;
        tm.tm_min = 61;
        tm.tm_sec = 0;
        tm.tm_isdst = -1;
        t = mktime(&tm);

mktime() should not return -1 in this case, because the time specified
does in fact exist, after normalization.  The normalized time in `tm'
should be 2002-04-07T03:02, with tm_isdst positive, which certainly
does exist.  The current code does not do this.  Even worse, the
current code returns an error even if tm_isdst is explicitly zero or
positive, which should be enough to explicitly identify the time in
question.

-GAWollman


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200204102028.g3AKS5h68482>