Anonymous user
Day of the week: Difference between revisions
→{{header|C}}: Change from strptime() to a manual calculation. Last Fridays of year#C had similar change.
(another ocaml solution using a dedicated library) |
(→{{header|C}}: Change from strptime() to a manual calculation. Last Fridays of year#C had similar change.) |
||
Line 231:
=={{header|C}}==
Because of problems with various C libraries (such as ''time_t'' overflowing during 2038, or strptime() or mktime() not filling in ''tm_wday''), this program uses [http://mathforum.org/library/drmath/view/62324.html Zeller's Rule] to calculate day of week.
<lang c>#include <
/* Calculate day of week in proleptic Gregorian calendar. Sunday == 0. */
int wday(int year, int month, int day)
{
int adjustment, mm, yy;
adjustment = (14 - month) / 12;
mm = month + 12 * adjustment - 2;
yy = year - adjustment;
return (day + (13 * mm - 1) / 5 +
yy + yy / 4 - yy / 100 + yy / 400) % 7;
}
int main()
{
int y;
for (y = 2008; y <= 2121; y++) {
}
|