Inverse for gmtime() ??

Nathan Myers ncm at cantrip.org
Wed Jan 22 00:07:24 UTC 1997


Chris Newman <Chris.Newman at innosoft.com>:
> On Mon, 20 Jan 1997, Markus G. Kuhn wrote:
> > I just wanted to start writing a ISO 8601 subset -> time_t conversion
> > routine, but to my great disappointment I discovered that ISO C does
> > not seem to allow portable conversion of a broken-down time into time_t.
> 
> You can do a binary search of the time_t space using the gmtime()
> function.  This does require the assumption that time_t is an integral
> type, but works well.

There is no reason to assume that time_t is integral, and good reasons
to assume it often is not, and more often in the future than at present.

The restricted range of 32-bit time_t values is a problem in common
applications, and until 64-bit machines are universal the easiest way
to sidestep the problem is "typedef double time_t;".  In any case, 
since time is a continuous quantity a floating-point representation 
makes perfect sense, and ANSI (aware of this) permits it.


Nathan Myers
ncm at cantrip.org



More information about the tz mailing list