From: mhiroshi@tansei.cc.u-tokyo.ac.jp (H. Murakami)
Newsgroups: fj.os.386bsd
Subject: Fix for the date bug 1993.
Date: 2 Jan 93 06:46:18 GMT
Distribution: fj
Organization: Hokkaido Univ. However I am subject to tansei for JUNET.

To: fj.os.386bsd
Subject: Fix for the date bug.

$B1<G/4XO"$N%"%k%4%j%:%`$N8m$j$K$h$j(J1993$BG/$+$i;~7W$NF|IU$,68$&(J .
$B0J2<$N(J $B%P%0(JFIX patch $B$r(J i386/isa/clock.c  $B$KEv$F$F$/$@$5$$(J.

(PC98$BHG$O$I$&$@$m$&(J?)
-------------------------------------------------------------------------------
                         $BJbJbJbJbJbJbJbJbJb(J              $BB<>e(J   $B90(J
PPPPPPPP                   $B3Q(J          $BHt(J
RNBQKBNR                 $B9a7K6d6b6L6b6d7K9a(J   mhiroshi@tansei.cc.u-tokyo.ac.jp

=======> QUOTE FOLLOWS <===========
From: ache@astral.msk.su (Andrew A. Chernov, Black Mage)
Newsgroups: comp.unix.bsd
Subject: [386bsd] New Year patch for CMOS clock, was still 92 year
Date: 1 Jan 93 09:28:37 GMT
Reply-To: ache@astral.msk.su
Organization: Ha-oh-lahm Yetzirah
Status: R

Hi,
I look today at my computer and see, that still 92 year now active :-(
Here is a patch to fix it (I was mathematician and remember,
that (y % 4) operation need whole year instead of (y - 1970),
moreover (y % 4) determinition of leap year is wrong,
see #define isleap() below for correct implementation).
This patch fix another small problem too, old code add 9x additional
seconds in any case: (sec += ytos(sec) instead of sec = ytos(sec))

P.S.: Happy New Year!

*** clock.c.was	Sun Nov 22 02:52:30 1992
--- clock.c	Fri Jan  1 12:17:04 1993
***************
*** 58,63 ****
--- 58,65 ----
  #define DAYST 119
  #define DAYEN 303
  
+ #define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
+ 
  startrtclock() {
  	int s;
  
***************
*** 94,102 ****
  	int i;
  	unsigned long ret;
  
! 	ret = 0; y = y - 70;
! 	for(i=0;i<y;i++) {
! 		if (i % 4) ret += 365*24*60*60;
  		else ret += 366*24*60*60;
  	}
  	return ret;
--- 96,104 ----
  	int i;
  	unsigned long ret;
  
! 	ret = 0;
! 	for(i=1970;i<y;i++) {
! 		if (!isleap(i)) ret += 365*24*60*60;
  		else ret += 366*24*60*60;
  	}
  	return ret;
***************
*** 145,152 ****
  	while ((sa&RTCSA_TUP) == RTCSA_TUP)
  		sa = rtcin(RTC_STATUSA);
  
! 	sec = bcd(rtcin(RTC_YEAR));
! 	leap = !(sec % 4); sec += ytos(sec); /* year    */
  	yd = mtos(bcd(rtcin(RTC_MONTH)),leap); sec += yd;	/* month   */
  	t = (bcd(rtcin(RTC_DAY))-1) * 24*60*60; sec += t; yd += t; /* date    */
  	day_week = rtcin(RTC_WDAY);				/* day     */
--- 147,154 ----
  	while ((sa&RTCSA_TUP) == RTCSA_TUP)
  		sa = rtcin(RTC_STATUSA);
  
! 	t = bcd(rtcin(RTC_YEAR)) + 1900;
! 	leap = isleap(t); sec = ytos(t); /* year    */
  	yd = mtos(bcd(rtcin(RTC_MONTH)),leap); sec += yd;	/* month   */
  	t = (bcd(rtcin(RTC_DAY))-1) * 24*60*60; sec += t; yd += t; /* date    */
  	day_week = rtcin(RTC_WDAY);				/* day     */
***************
*** 153,159 ****
  	sec += bcd(rtcin(RTC_HRS)) * 60*60;			/* hour    */
  	sec += bcd(rtcin(RTC_MIN)) * 60;			/* minutes */
  	sec += bcd(rtcin(RTC_SEC));				/* seconds */
- 	sec -= 24*60*60; /* XXX why ??? */
  
  	/* XXX off by one? Need to calculate DST on SUNDAY */
  	/* Perhaps we should have the RTC hold GMT time to save */
--- 155,160 ----
-- 
In-This-Life:  Andrew A. Chernov    |  "Hay mas dicha, mas contento
Internet:      ache@astral.msk.su   |  "Que adorar una hermosura
Organization:  The RELCOM Corp.,    |  "Brujuleada entre los lejos
               Moscow, Russia       |  "De lo imposible?!"  (Calderon)