fixed incorrect fday handling in dayofweek() function

This commit is contained in:
Willem van de Krol 2014-07-04 22:23:52 +02:00 committed by sin
parent 5721deb2c4
commit f02f2190f0

12
cal.c
View File

@ -79,15 +79,11 @@ drawcal(int year, int month, int day, int ncols, int nmons, int fday)
static int static int
dayofweek(int year, int month, int day, int fday) dayofweek(int year, int month, int day, int fday)
{ {
int a, y, m, d; static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
month++; day += 7 - fday;
a = (14 - month) / 12; year -= month < 2;
y = year + 4800 - a; return (year + year / 4 - year / 100 + year / 400 + t[month] + day) % 7;
m = month + 12 * a - 3;
d = (day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y \
/ 400 - 32045 + 1) % 7;
return (fday > d)? (7 - d) : (d - fday);
} }
static bool static bool