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

Wolfgang S. Rupprecht wolfgang+gnus20031109T151853 at dailyplanet.dontspam.wsrcc.com
Sun Nov 9 23:29:28 UTC 2003


Hans Jørgen Jakobsen <hjj at wheel.dk> writes:
> On Sun, 09 Nov 2003 20:14:15 GMT, Wolfgang S. Rupprecht wrote:
>> 
>> Hans Jørgen Jakobsen <hjj at wheel.dk> writes:
>>>>       dectimet = timegm ( &dectime );
>> 
>> Thanks for posting this.  I hadn't realized that libc() had an
>> undocumented utc version of mktime().  Up to this point I'd been using
>> this following hack to fix up the offset.
>> 
>>     tm->tm_isdst = -1;
>>     time = mktime(tm);
>>     if (time >= 0) {
>> 	time += tm->tm_gmtoff;
>>     } 
>> 
>> Seeing how much work libc/time/localtime.c:mktime() does to generate
>> the time with the offset, using timegm() is clearly superior.
>
> Your have a point in that timegm is non std. A closer look at the FreeBSD
> man page conformed that its non std. ANd as far as i can see its not present
> in Solaris 8 (At least not in the man pages)

Unix really needs a lightweight UTC_tm to seconds_since_the_epoch
routine.  Documenting and using it is the best way to get it into the
mainstream.  I'm going to try to see if I can get netbsd to document
the timegm() routine and perhaps put a note in the man page that it is
more lightweight than using mktime().

> I have some trouble convincing myself that there ar no bugs lurking in the
> code above. What happens when we are changing summertime/normaltime?? 

My reasoning when as such: At some point during the DST transition
mktime decides that the converted time is on one side of the
transition or not.  It will note the offset it used in calculating the
time.  The beauty is, even if mktime()'s DST tables are messed up in
terms of when the DST change takes place, the offset is always
consistent with what it used in the calculation.  Adding the offset
into the time should always give one the raw UTC time.

Comments?

-wolfgang
-- 
Wolfgang S. Rupprecht 		     http://www.wsrcc.com/wolfgang/
           The From: address is valid.  Don't mess with it.



More information about the questions mailing list