*BSD News Article 9876


Return to BSD News archive

Received: by minnie.vk1xwt.ampr.org with NNTP
	id AA6699 ; Tue, 12 Jan 93 08:08:19 EST
Path: sserve!manuel.anu.edu.au!munnari.oz.au!sgiblab!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!unidui!du9ds4!prang
From: prang@du9ds4.fb9dv.uni-duisburg.de (Juergen Prang)
Newsgroups: comp.unix.bsd
Subject: Re: problems with date
Date: 14 Jan 93 20:35:13 GMT
Organization: Universitaet Duisburg GH
Lines: 118
Message-ID: <prang.727043713@du9ds4>
References: <1iu2jsINN518@fbi-news.Informatik.Uni-Dortmund.DE> <1993Jan14.064517.7201@st.simbirsk.su>
NNTP-Posting-Host: du9ds4.fb9dv.uni-duisburg.de

cliff@st.simbirsk.su (Viacheslav Andreev) writes:

>Ulrich Joergens (PG211) (joergens@snorre.informatik.uni-dortmund.de) wrote:
>: I am in trouble with date. The time is set correct but the day is set to 
>: 'yesterday' so I'm 24 hours to late. The timezone in my config file is set
>: to -1 dst.
>I have the same trouble (timezone is set to -3 dst).

>--
>Viacheslav Andreev
>Dimitrovgrad town, Middle Volga, Russia.

Okay, here is the patch originally posted by Andrew on Jan 1st. Apply it
to clock.c and rebuild your kernel.

Hope this helps (after all it does for me :-)
Juergen

**************** original posting follows *******************

Path: unidui!math.fu-berlin.de!ira.uka.de!yale.edu!spool.mu.edu!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)


**************** end of original posting ********************
-- 
   Juergen Prang           | INTERNET: prang@du9ds4.fb9dv.uni-duisburg.de
   University of Duisburg  | BITNET: prang%du9ds4.fb9dv.uni-duisburg.de@UNIDO
   EE - Dept. of Dataprocessing - Bismarckstr. 81 - D-4100 Duisburg 1