[comp.sys.sun] Patch for calentool

gore@eecs.nwu.edu (Jacob Gore) (01/07/89)

There is a bug in calentool that showed up when 1989 rolled around.  The
symptom is that it believes that today is yesterday.

The fundamental problem is in array year_days in utils.c.  They key is
that each location stores the number of days between the beginning of 1985
and the BEGINNING of the year, not to its end.  Thus, the fact that 1988
is a leap year adds 1 to 1989's location, not to 1988 (in the beginning of
1988, the leap year has not taken toll yet).

This, of course, should have made it NOT work in 1988, because in 1988 an
extra day is added, and work again in 1989, because in 1989 one day too
few is added, to make it in step again.  My feeling is that it didn't work
in 1988, and that's why there is a "- 1" in the computation, to compensate
for the bug.  The "- 1" screws things up in 1989, however. 

The following patch fixes that data in the array, and removes the "- 1",
which I very strongly suspect to be a kluge.

[[ I have received messages from several readers complaining about the
same bug.  This was the only one with a patch.  I don't intend to post the
other messages for obvious reasons.  Thanks to all who pointed out the
problem and worked on debugging it.  --wnl ]]

Jacob Gore				Gore@EECS.NWU.Edu
Northwestern Univ., EECS Dept.		{oddjob,gargoyle,att}!nucsrl!gore

*** /tmp/,RCSt1005087	Wed Jan  4 23:17:51 1989
--- utils.c	Wed Jan  4 23:02:30 1989
***************
*** 90,97 ****

  /* cummulative number of days since Jan 1, 1985 by years to 1999 */
  /* (takes into account leap years in 1988, 1992, 1996) */
! int year_days[] = {0, 365, 730, 1096, 1461, 1826, 2191, 2557, 2922,
! 			3287, 3652, 4018, 4383, 4748, 5113};

  get_today()
  {
--- 90,97 ----

  /* cummulative number of days since Jan 1, 1985 by years to 1999 */
  /* (takes into account leap years in 1988, 1992, 1996) */
! int year_days[] = {0, 365, 730, 1095, 1461, 1826, 2191, 2556, 2922,
! 			3287, 3652, 4017, 4383, 4748, 5113};

  get_today()
  {
***************
*** 101,107 ****

  	gettimeofday(&tv, 0);
  	tm = localtime(&tv.tv_sec);
! 	t = tm->tm_yday + year_days[tm->tm_year-85] - year_days[START_YEAR-85] - 1;
  	return(t);
  }

--- 101,107 ----

  	gettimeofday(&tv, 0);
  	tm = localtime(&tv.tv_sec);
! 	t = tm->tm_yday + year_days[tm->tm_year-85] - year_days[START_YEAR-85];
  	return(t);
  }