home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / unix / bsd / 10813 < prev    next >
Encoding:
Internet Message Format  |  1993-01-01  |  2.8 KB

  1. Path: sparky!uunet!mcsun!fuug!kiae!demos!newsserv
  2. From: "Andrew A. Chernov, Black Mage" <ache@astral.msk.su>
  3. Newsgroups: comp.unix.bsd
  4. Subject: [386bsd] New Year patch for CMOS clock, was still 92 year
  5. Date: Fri, 01 Jan 93 12:28:37 +0300
  6. Distribution: world
  7. Organization: Ha-oh-lahm Yetzirah
  8. Message-ID: <DG5x0Hha50@astral.msk.su>
  9. Sender: news-service@newcom.kiae.su
  10. Reply-To: ache@astral.msk.su
  11. Lines: 80
  12.  
  13. Hi,
  14. I look today at my computer and see, that still 92 year now active :-(
  15. Here is a patch to fix it (I was mathematician and remember,
  16. that (y % 4) operation need whole year instead of (y - 1970),
  17. moreover (y % 4) determinition of leap year is wrong,
  18. see #define isleap() below for correct implementation).
  19. This patch fix another small problem too, old code add 9x additional
  20. seconds in any case: (sec += ytos(sec) instead of sec = ytos(sec))
  21.  
  22. P.S.: Happy New Year!
  23.  
  24. *** clock.c.was    Sun Nov 22 02:52:30 1992
  25. --- clock.c    Fri Jan  1 12:17:04 1993
  26. ***************
  27. *** 58,63 ****
  28. --- 58,65 ----
  29.   #define DAYST 119
  30.   #define DAYEN 303
  31.   
  32. + #define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
  33.   startrtclock() {
  34.       int s;
  35.   
  36. ***************
  37. *** 94,102 ****
  38.       int i;
  39.       unsigned long ret;
  40.   
  41. !     ret = 0; y = y - 70;
  42. !     for(i=0;i<y;i++) {
  43. !         if (i % 4) ret += 365*24*60*60;
  44.           else ret += 366*24*60*60;
  45.       }
  46.       return ret;
  47. --- 96,104 ----
  48.       int i;
  49.       unsigned long ret;
  50.   
  51. !     ret = 0;
  52. !     for(i=1970;i<y;i++) {
  53. !         if (!isleap(i)) ret += 365*24*60*60;
  54.           else ret += 366*24*60*60;
  55.       }
  56.       return ret;
  57. ***************
  58. *** 145,152 ****
  59.       while ((sa&RTCSA_TUP) == RTCSA_TUP)
  60.           sa = rtcin(RTC_STATUSA);
  61.   
  62. !     sec = bcd(rtcin(RTC_YEAR));
  63. !     leap = !(sec % 4); sec += ytos(sec); /* year    */
  64.       yd = mtos(bcd(rtcin(RTC_MONTH)),leap); sec += yd;    /* month   */
  65.       t = (bcd(rtcin(RTC_DAY))-1) * 24*60*60; sec += t; yd += t; /* date    */
  66.       day_week = rtcin(RTC_WDAY);                /* day     */
  67. --- 147,154 ----
  68.       while ((sa&RTCSA_TUP) == RTCSA_TUP)
  69.           sa = rtcin(RTC_STATUSA);
  70.   
  71. !     t = bcd(rtcin(RTC_YEAR)) + 1900;
  72. !     leap = isleap(t); sec = ytos(t); /* year    */
  73.       yd = mtos(bcd(rtcin(RTC_MONTH)),leap); sec += yd;    /* month   */
  74.       t = (bcd(rtcin(RTC_DAY))-1) * 24*60*60; sec += t; yd += t; /* date    */
  75.       day_week = rtcin(RTC_WDAY);                /* day     */
  76. ***************
  77. *** 153,159 ****
  78.       sec += bcd(rtcin(RTC_HRS)) * 60*60;            /* hour    */
  79.       sec += bcd(rtcin(RTC_MIN)) * 60;            /* minutes */
  80.       sec += bcd(rtcin(RTC_SEC));                /* seconds */
  81. -     sec -= 24*60*60; /* XXX why ??? */
  82.   
  83.       /* XXX off by one? Need to calculate DST on SUNDAY */
  84.       /* Perhaps we should have the RTC hold GMT time to save */
  85. --- 155,160 ----
  86. -- 
  87. In-This-Life:  Andrew A. Chernov    |  "Hay mas dicha, mas contento
  88. Internet:      ache@astral.msk.su   |  "Que adorar una hermosura
  89. Organization:  The RELCOM Corp.,    |  "Brujuleada entre los lejos
  90.                Moscow, Russia       |  "De lo imposible?!"  (Calderon)
  91.  
  92.