Subject: Re: Timezones
To: None <amiga@NetBSD.ORG>
From: Petri Nordlund <petrin@mits.mdata.fi>
List: amiga
Date: 11/14/1994 17:47:28
There was a discussion about timezones some time ago on this list.
I quote the original message:

  From: Karl-Gunnar Hultland <dixie@Krille.Update.UU.SE>
  Subject: Timezones
  Date: Thu, 29 Sep 1994 18:39:23 +0100 (MET)

  Can I patch the Kernel for it to use a
  different timezone? Or is it possible to
  add such an option into the iteconfig 
  program. As it is now, I have to choose
  if the Amiga side or the Unix side will 
  get the correct time.

I have also run into same problem. I use a lot of astronomical applications
(satellite tracking etc..) on both AmigaDos and NetBSD-side. The time must
be correct on both sides to get usefull results from these programs. If
the hardware clock is set to local time, then the timezone in NetBSD
must be GMT, but some programs need correct timezone to work. The
hardware clock can be set to GMT but then the time in AmigaDos is
incorrect.

So, to make both sides operate properly, the hardware clock must be kept
at local time but the time given to kernel must be GMT. I modified
the a3gettod() and a2gettod() routines in sys/arch/amiga/dev/clock.c
to calculate GMT from local time. I also patched the settod()-routines
to convert GMT to local time, but these routines arenīt currently used.

So, apply the following patches and set the hours_from_gmt -variable
to proper value. This is correctly `positive eastī, not `positive
westī like in some USA-made astronomy programs. I.e. if you live
east of Greenwich, you set this to positive value (I live in Finland
where we use EET which is GMT+2, so I use +2). This patch doesnīt
know anything about DST, so you have to change the value twice a year.

Then recompile, set your hardware clock to your local time, reboot and
link /etc/timezone to approriate timezone-file in /usr/share/zoneinfo/.

There is one problem, if the time/date on a ufs or nfs partition is
more recent than your clock, kernel assumes that the time in the
ufs or nfs partition is correct. This should only affect people in
the western hemisphere. You can disable the checking, itīs in
inittodr()-routine in clock.c:

	if (timbuf < base) {
		printf("WARNING: bad date in battery clock\n");
		timbuf = base;
	}

This will go away in a few hours if you donīt reboot before that.

The hours_from_gst -variable can also be modified with binpatch:

  binpatch -l -s _hours_from_gst -r <hours> netbsd

And finally, here are the diffs, they are for NetBSD-1.0:


diff -pc clock.c.orig clock.c
*** clock.c.orig	Mon Nov  7 22:39:47 1994
--- clock.c	Mon Nov  7 22:39:47 1994
***************
*** 56,61 ****
--- 56,66 ----
  #include <sys/PROF.h>
  #endif
  
+ /* Hardware clock can be kept at local time when this value is set to
+  * number of hours from GMT.
+  */
+ long hours_from_gmt = 2;		/* timezone is GMT+2 (EET) */
+ 
  /* the clocks run at NTSC: 715.909kHz or PAL: 709.379kHz. 
     We're using a 100 Hz clock. */
  
*************** a3gettod()
*** 742,748 ****
  	tmp += (day - 1);
  	tmp = ((tmp * 24 + hour) * 60 + min) * 60 + sec;
  
! 	return(tmp);
  }
  
  int
--- 747,753 ----
  	tmp += (day - 1);
  	tmp = ((tmp * 24 + hour) * 60 + min) * 60 + sec;
  
! 	return(tmp - (hours_from_gmt * 60 * 60));
  }
  
  int
*************** a3settod(tim)
*** 759,764 ****
--- 764,771 ----
  	u_char year1, year2;
  	struct rtclock3000 *rt;
  
+ 	tim += hours_from_gmt * 60 * 60;
+ 
  	rt = clockaddr;
  	/*
  	 * there seem to be problems with the bitfield addressing
*************** a2gettod()
*** 886,892 ****
  	tmp += (day - 1);
  	tmp = ((tmp * 24 + hour) * 60 + min) * 60 + sec;
    
! 	return(tmp);
  }
  
  /*
--- 893,899 ----
  	tmp += (day - 1);
  	tmp = ((tmp * 24 + hour) * 60 + min) * 60 + sec;
    
! 	return(tmp - (hours_from_gmt * 60 * 60 ));
  }
  
  /*
*************** a2settod(tim)
*** 907,912 ****
--- 914,921 ----
  	u_char mon1, mon2;
  	u_char year1, year2;
  	struct rtclock2000 *rt;
+ 
+ 	tim += hours_from_gmt * 60 * 60;
  
  	rt = clockaddr;
  	/* 


Petri

--                                 __
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~///~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Petri Nordlund          __///         petrin@mits.mdata.fi
 ------------------------------\XX/-------------------------------------