[comp.sources.bugs] Daylight savings time and congress

dg@lakart.UUCP (David Goodenough) (02/13/89)

I recently posted a DST check program / subroutine, based on a quote
that stated that "DST starts the last Sunday in April, and ends the
last Sunday in October". I have been informed that Congress changed
the rules in 1987, and that is no longer valid. DST _NOW_ begins
the first Sunday in April. Hence I provide a revised isdst()
subroutine to respect this.

My apologies for misleading everyone on the basis of out of date
information. (-: I will hit myself over the head with a sock full of
cold custard, 27 times as pennance. :-)
-- 
	dg@lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp@xait.xerox.com		  	  +---+

--- cut here --- cut here --- cut here --- cut here --- cut here ---
main(n, a)
char **a;
 {
    int i, j;

    j = atoi(a[1]);

    for (i = 1; i <= 10; i++)
      printf("%d %d %d %d: %d\n", i, 4, j, 19, isdst(i, 4, j, 19));
    putchar('\n');
    for (i = 21; i <= 31; i++)
      printf("%d %d %d %d: %d\n", i, 10, j, 19, isdst(i, 10, j, 19));
 }

/*
 * isdst(day, month, year, century)
 * feed in numbers as you'd expect: today (2-12-1989) would be
 * isdst(12, 2, 89, 19)
 */
isdst(d, m, y, c)
 {
    if (m > 4 && m < 10)
      return(1);	/* May thru Sept are always dst */
    if (m == 10)
     {			/* Oct - see if there's a Sunday after given day */
	while (++d <= 31)
	  if (dayofweek(d, m, y, c) == 0)
	    return(1);	/* yes, so it is dst */
     }
    else if (m == 4)
     {			/* April - see if there's a Sunday beforegiven day */
	while (d >= 1)
	  if (dayofweek(d--, m, y, c) == 0)
	    return(1);	/* yes, so this is also dst */
     }
    return(0);		/* either Jan - Mar, Nov, Dec, or no good in Apr
			 * or Oct */
 }

dayofweek(d, m, y, c)
 {
    if ((m = m - 2) < 1)
     {
	m = m + 12;
	if (y-- == 0)
	 {
	    y = 99;
	    c--;
	 }
     }
    return(((13 * m - 1) / 5 + d + y + y / 4 + c / 4 - 2 * c) % 7);
			/* don't ask. Just trust me: it does work */
 }