mktime() failure vs 31-DEC-1969 23:59:59 GMT
tomp at zk3.dec.com
tomp at zk3.dec.com
Fri Feb 16 17:11:21 UTC 1996
> >> Call localtime() on the seemingly-in-error mktime() result, and compare
> >> the relevant portions of the structs tm. A match implies a non-error.
>
> > This doesn't sound very stable, but perhaps there is no other alternative.
>
> I'm not sure of what you mean by stable. This is, after all, exactly what
> mktime() does to determine is has the matching time_t.
Arthur's response to your mail (included below) addresses this with
respect to normalization. Also, who's to say that localtime() should
return a meaningful tm struct when given a -1 input? The standards
don't require it handle this case. If localtime() doesn't return a
reasonable tm struct, that still doesn't automatically imply that the
previous call to mktime() (returning -1) was a failure as well. The
underlying engine for each routine may not be the same, so I don't
think you can make this assumption.
- Tom
------- Forwarded Message
Date: Wed, 14 Feb 96 13:00:02 EST
From: ado at elsie.nci.nih.gov (Arthur David Olson)
Message-Id: <9602141800.AA06443 at elsie.nci.nih.gov>
To: bww at fore.com, tomp at zk3.dec.com
Subject: Re: mktime() failure vs 31-DEC-1969 23:59:59 GMT
Cc: tz at elsie.nci.nih.gov
> > The standards for mktime() define a return value of
> > (time_t)-1 as indicating that the time specified cannot be
> > represented. However, a return value of -1 is also a valid time_t
> > corresponding to 31-DEC-1969 23:59:59 GMT. How do we distinguish
> > between the two?
>
> Call localtime() on the seemingly-in-error mktime() result, and compare
> the relevant portions of the structs tm. A match implies a non-error.
Since there's normalization going on in mktime, the tm that comes back from
localtime may not match the one that went in to mktime even if -1 is being
returned as a legitimate time_t rather than an error indication.
Another possibility is to save away the original tm structure; if mktime
returns -1, bump the tm_sec value by 1, call mktime again, and see if it
returns zero.
--ado
------- End of Forwarded Message
More information about the tz
mailing list