Subject: Re: clock?
From: Bill Fink (bill@capu.net)
Date: Sat Nov 11 2000 - 01:42:22 MST
> R Shapiro wrote:
>
> So what is the answer to the persistent off-by-an-hour mol clock bug,
> which appeared at the end of daylight-savings-time? Is there an
> answer?
I have a patch for this:
--- mol-0.9.52/emulation/os_interface.c Mon Oct 23 16:17:09 2000
+++ mol-0.9.52+/emulation/os_interface.c Sat Nov 11 02:22:08 2000
@@ -194,12 +194,13 @@
{
#if 1
time_t gmt;
+ struct tm *ltime;
gmt = time( NULL );
- (void) localtime( &gmt );
+ ltime = localtime( &gmt );
/* 1904 -> 1970 conversion with time zone adjustment */
- return gmt + 0x7C25B080 - timezone + (daylight? 3600: 0);
+ return gmt + 0x7C25B080 - timezone + (ltime->tm_isdst ? 3600 : 0);
#else
/* 1904 -> 1970 conversion */
return time( NULL ) + 0x7C25BE85;
There appears to be a bug in the localtime function. It always
returns 1 for the external daylight variable, but correctly returns
0 or 1 in the tm_isdst element of the tm structure, depending on
whether or not Daylight Savings Time is in effect.
This is evidenced by the following test program:
/* test_localtime.c */
#include <time.h>
main( argc, argv )
{
time_t gmt;
struct tm *ltime;
gmt = 0x382bdae0;
printf("gmt = %0lX\n", gmt);
printf("date = %s", ctime( &gmt ));
ltime = localtime( &gmt );
printf("timezone = %d, daylight = %d\n", timezone, daylight);
printf("tm_isdst = %d\n", ltime->tm_isdst);
gmt = 0x38f6eff0;
printf("gmt = %0lX\n", gmt);
printf("date = %s", ctime( &gmt ));
ltime = localtime( &gmt );
printf("timezone = %d, daylight = %d\n", timezone, daylight);
printf("tm_isdst = %d\n", ltime->tm_isdst);
gmt = 0x3a0bbce0;
printf("gmt = %0lX\n", gmt);
printf("date = %s", ctime( &gmt ));
ltime = localtime( &gmt );
printf("timezone = %d, daylight = %d\n", timezone, daylight);
printf("tm_isdst = %d\n", ltime->tm_isdst);
gmt = 0x3ad6d1f0;
printf("gmt = %0lX\n", gmt);
printf("date = %s", ctime( &gmt ));
ltime = localtime( &gmt );
printf("timezone = %d, daylight = %d\n", timezone, daylight);
printf("tm_isdst = %d\n", ltime->tm_isdst);
exit( 0 );
}
The gmt values were chosen to be 0x100000 more than the recent past
and near future transition times from my /etc/localtime time zone
file (which is US/Eastern). Here is the output of test_localtime:
gmt = 382BDAE0
date = Fri Nov 12 04:16:16 1999
timezone = 18000, daylight = 1
tm_isdst = 0
gmt = 38F6EFF0
date = Fri Apr 14 06:16:16 2000
timezone = 18000, daylight = 1
tm_isdst = 1
gmt = 3A0BBCE0
date = Fri Nov 10 04:16:16 2000
timezone = 18000, daylight = 1
tm_isdst = 0
gmt = 3AD6D1F0
date = Fri Apr 13 06:16:16 2001
timezone = 18000, daylight = 1
tm_isdst = 1
BTW, I noticed that I can no longer "rmmod mol", as it indicates
it's busy, even though I shut down MOL normally. I was wondering
if this was something we had to live with now, or if it might be
something easy to fix.
-Bill Fink
This archive was generated by hypermail 2a24 : Sat Nov 11 2000 - 01:42:47 MST