Inverse for gmtime() ??

Markus G. Kuhn kuhn at cs.purdue.edu
Mon Jan 20 23:05:08 UTC 1997


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?

In case someone of you is in contact with the folks revising ISO C, I have
now a whole list of things that should be fixed in time.h:

- add inverse function for gmtime() (mkutime() or mkgmtime())
- add to strftime() conversion specifiers for ISO 8601 week-of-year
  and year-of-week.
- remove the second leap second 61 mentioned in the footnote
  (contradicts to UTC definition)

Instead of adding an inverse function for gmtime, one could also extend
struct tm by a new field tm_offset, which is in seconds the difference
between the time in the struct tm and the corresponding universal time
(in my opinion a much cleaner solution than the tm_isdst hack).
But I guess, this might break existing code that does not initialize
tm_offset ...

Having a tm_offset in struct tm would however still be a good idea as this
would allow to implement in strftime() conversion specifiers for the
time zone offset (much more interesting than the time zone name).

Markus

-- 
Markus G. Kuhn, Computer Science grad student, Purdue
University, Indiana, USA -- email: kuhn at cs.purdue.edu





More information about the tz mailing list