the day of week for any date. The algorithm for a zero based day of week:
calculate the number of days in all prior years (year-1)*365
- add the number of leap years (days?) since year 1
+ add the number of leap years (days?) since year 1
(not including this year as that is covered later)
add the day number within the year
this compensates for the non-inclusive leap year
calculation
if the day in question occurs before the gregorian reformation
- (3 sep 1752 for our purposes), then simply return
+ (3 sep 1752 for our purposes), then simply return
(value so far - 1 + SATURDAY's value of 6) modulo 7.
if the day in question occurs during the reformation (3 sep 1752
to 13 sep 1752 inclusive) return THURSDAY. This is my
-/* $OpenBSD: cal.c,v 1.31 2022/12/04 23:50:47 cheloha Exp $ */
+/* $OpenBSD: cal.c,v 1.32 2024/08/18 19:58:35 deraadt Exp $ */
/* $NetBSD: cal.c,v 1.6 1995/03/26 03:10:24 glass Exp $ */
/*
shift = 1;
if (yearday < firstsunday)
return (1);
- if (firstweekday > THURSDAY - 1)
+ if (firstweekday > THURSDAY - 1)
shift = 2;
return ((((yearday + 1) - (weekday - 1)) / 7) + shift);
}
return 53 - (g - s) / 5;
else if (n > 364 + s)
return 1;
- else
+ else
return n/7 + 1;
}