[ntp:questions] Re: Jonathan Buzzard's radioclkd and FreeBSD

Terje Mathisen terje.mathisen at hda.hydro.com
Tue Nov 11 09:28:29 UTC 2003


Wolfgang S. Rupprecht wrote:

> Terje Mathisen <terje.mathisen at hda.hydro.com> writes:
>>The only real problem in that direction is the leap handling, the rest
>>is just a couple of multiplications and a month-table lookup.
> 
> Thanks.  I'll keep that code (and correction) for reference.

You're welcome!

The really fun part is to make a fast & correct implementation of the 
reverse operation, going from time_t secs (or Julian day number) to 
Y-M-D, while handling all those leap year rules.

My fastest code to do this works by first guessing the year, then doing 
the (fast) reverse calculation and then, if needed, adjust the year by one.

It is portable to all binary machines with at least 29-bit unsigned 
integers, i.e. it works on ones-complement and sign+mantissa as well as 
regular twos-complement cpus.

Terje
-- 
- <Terje.Mathisen at hda.hydro.com>
"almost all programming can be viewed as an exercise in caching"




More information about the questions mailing list