This is the mail archive of the
libc-hacker@sourceware.cygnus.com
mailing list for the glibc project.
Re: BUG in mktime (PR libc/783)
- To: Andreas Jaeger <jaeger@gnu.org>
- Subject: Re: BUG in mktime (PR libc/783)
- From: Ulrich Drepper <drepper@cygnus.com>
- Date: 05 Oct 1998 18:44:26 -0700
- Cc: libc-hacker@cygnus.com, Michael Deutschmann <michael@talamasca.wkpowerlink.com>, Jim Meyering <meyering@eng.ascend.com>
- References: <199809180749.DAA04249@delysid.gnu.org>
- Reply-To: drepper@cygnus.com (Ulrich Drepper)
Andreas Jaeger <jaeger@gnu.org> writes:
> Michael reported a bug in mktime. You can reproduce it with:
> $ TZ=America/Vancouver date --date="Apr 5 3:00 1 hour ago"
> date: invalid date `Apr 5 3:00 1 hour ago'
The problem is that mktime returns on other systems (e.g, Solaris) for
the illegal broken down date
Apr 5 2:00
a non-error value. A simple program printing the values for 1:00,
2:00 and 3:00 executed on Solaris 2.7 results in
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t1 = 891766800, t2 = 891766800, t3 = 891774000
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With glibc it results in
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t1 = 891766800, t2 = -1, t3 = 891770400
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I think the glibc interpretation is at least equally well. The mktime
specification says it returns -1 if the date cannot be represented.
This is the case for the illegal date 2:00.
To get GNU date running I think it should be possible to do something
like this:
t = mktime (tp);
if (t == -1)
{
substract one hour from `tp'
t1 = mktime (tp);
add two hours to `tp'
t2 = mktime (tp);
if (t1 != -1 && t2 != -1 && t2 - t1 == 3600)
{
...handle DST switch correctly...
}
}
In this case the program can decide whether it is 1:59, 3:00, or 1:59,
2:00, 3:01. Maybe the case where yyRelHour etc is != 0 needs some
special handling but this is the only really portable way. Relying on
mktime to return a useful value for an illegal data is not correct.
--
---------------. drepper at gnu.org ,-. 1325 Chesapeake Terrace
Ulrich Drepper \ ,-------------------' \ Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com `------------------------