Inverse for gmtime() ??

Markus G. Kuhn kuhn at
Wed Jan 22 00:31:00 UTC 1997

In message <m0vmqDs-0002ndC at mill>, Nathan Myers wrote:

> Chris Newman <Chris.Newman at>:
> > 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.

As the successful student of a numerical analysis course, I had
of course considered first to implement a finite difference variant
of Newton's algorithm to find a zero crossing for X in the function
distance(gmtime(X), my_brocken_down_time). This is very fast and
might work most of the time nicely with both integer and fp time_t.

But then I stepped back and saw that self-learning API usage code like
this is certainly pretty cool, but it is ridiculously bad software engineering
practice. I would never want to find code like this in so-called portable
software that I am supposed to port, and I'd probably fire a programmer
who implements a hack like this for me.  My code will contain a simple
conversion routine that assumes POSIX.1 and can easily be replaced by
whatever else your non-POSIX system uses.


p.s.: I fixed already the static buffer bug in the last posted version.

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

More information about the tz mailing list