Inverse for gmtime() ??
Chris Newman
Chris.Newman at innosoft.com
Tue Jan 21 18:43:14 UTC 1997
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.
>
> In other words, while mktime() is the inverse function to localtime(),
> there exists no mkgmtime() that is the inverse function to gmtime().
> I knew that the C standard library time API is a strange design, but I had
> no idea that it was *that* bad.
>
> The only practical way to get from a broken-down UTC time to time_t seems
> to be to assume that we are on a POSIX system where the time_t representation
> is exactly specified.
>
> Or did I miss something?
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. I have some source to do it, but it has two
copyrights on it. It'd be nice to have source in the date-time document
which was unencumbered...
More information about the tz
mailing list