Re: mktime() failure vs 31-DEC-1969 23:59:59 GMT
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.
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. No errors are defined for localtime() either, so we would be assuming that the tm info it returns is correct. Of course, we only need to check this when the return of mktime() is -1, so perhaps the risk/impact is minimal. However, it might make sense to add documentation to this effect to the manpage for mktime() so folks don't assume that a -1 return from mktime() always means that the time specified is not representable. thanks, - Tom
participants (2)
-
Bradley White -
tomp@zk3.dec.com