From: aizu@orient.center.nitech.ac.jp (Hiroyuki Aizu)
Subject: Re: Fix for the date bug 1993.
Organization: Nagoya Institute of Technology, Nagoya, Japan
Distribution: fj
Date: Mon, 4 Jan 1993 13:17:34 GMT

$@2qDE!wL>9)Bg$G$9!#(J

In article <3811@tansei1.tansei.cc.u-tokyo.ac.jp> mhiroshi@tansei.cc.u-tokyo.ac.jp (H. Murakami) writes:

   >$@1<G/4XO"$N%"%k%4%j%:%`$N8m$j$K$h$j(J1993$@G/$+$i;~7W$NF|IU$,68$&(J .
   >$@0J2<$N(J $@%P%0(JFIX patch $@$r(J i386/isa/clock.c  $@$KEv$F$F$/$@$5$$(J.
   >
   >(PC98$@HG$O$I$&$@$m$&(J?)

PC98$@HG$b(J$@%P%0$C$F$^$7$?!#(J
98$@HGMQ$K%Q%C%A$r$D$/$C$F$_$^$7$?!#(J
$@$3$N%Q%C%A$O(J Andrew Chernov$@;a$N%Q%C%A$r4^$s$G$$$^(J$@$9!#(J

BEGIN--cut here--cut here---------------------------------------------------
*** clock.c.original	Mon Jan  4 18:43:36 1993
--- clock.c	Mon Jan  4 20:43:13 1993
***************
*** 60,65 ****
--- 60,67 ----
  #define DAYST 119
  #define DAYEN 303
  
+ #define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
+ 
  startrtclock() {
  	int s;
  
***************
*** 113,121 ****
  	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;
--- 115,123 ----
  	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;
***************
*** 225,237 ****
  
   	year = bcd(rtc_inb()&0xff);	/* year */
  
! 	leap = !(year % 4); sec = ytos(year); /* year */
  	yd = mtos(month,leap); sec += yd;	/* month */
  	t = date * 24*60*60; sec += t; yd += t;	/* date */
  	sec += hour * 60*60;		/* hour */
  	sec += min  * 60;		/* minutes */
  	sec += second;			/* seconds */
- 	sec -= 24*60*60;	/* XXX why ??? */
  
  /*printf("DATE %2d/%2d/%2d (%2d) %2d:%2d:%2d JST\n",
  	year, month, date+1, day_week, hour, min, second );*/
--- 227,239 ----
  
   	year = bcd(rtc_inb()&0xff);	/* year */
  
! 	t = year + 1900;
! 	leap = isleap(t); sec = ytos(t);
  	yd = mtos(month,leap); sec += yd;	/* month */
  	t = date * 24*60*60; sec += t; yd += t;	/* date */
  	sec += hour * 60*60;		/* hour */
  	sec += min  * 60;		/* minutes */
  	sec += second;			/* seconds */
  
  /*printf("DATE %2d/%2d/%2d (%2d) %2d:%2d:%2d JST\n",
  	year, month, date+1, day_week, hour, min, second );*/
***************
*** 245,252 ****
  	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     */
--- 247,254 ----
  	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     */
***************
*** 253,259 ****
  	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 ??? */
  #endif
  
  #ifdef notdef
--- 255,260 ----
BEGIN--cut here--cut here---------------------------------------------------

--
                                $@2qDE!wL>9)(J$@Bg(J
                                aizu@orient.center.nitech.ac.jp