*BSD News Article 9468


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA5813 ; Fri, 01 Jan 93 01:56:42 EST
Path: sserve!manuel.anu.edu.au!munnari.oz.au!uunet!mcsun!fuug!kiae!demos!newsserv
From: "Andrew A. Chernov, Black Mage" <ache@astral.msk.su>
Newsgroups: comp.unix.bsd
Subject: [386bsd] New Year patch for CMOS clock, was still 92 year
Date: Fri, 01 Jan 93 12:28:37 +0300
Distribution: world
Organization: Ha-oh-lahm Yetzirah
Message-ID: <DG5x0Hha50@astral.msk.su>
Sender: news-service@newcom.kiae.su
Reply-To: ache@astral.msk.su
Lines: 80

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)