From f02f2190f064584ff838352a8ec1cc92dc191742 Mon Sep 17 00:00:00 2001 From: Willem van de Krol <008054@jfc.nl> Date: Fri, 4 Jul 2014 22:23:52 +0200 Subject: [PATCH] fixed incorrect fday handling in dayofweek() function --- cal.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cal.c b/cal.c index 8faf3de..a477db9 100644 --- a/cal.c +++ b/cal.c @@ -79,15 +79,11 @@ drawcal(int year, int month, int day, int ncols, int nmons, int fday) static int 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++; - a = (14 - month) / 12; - y = year + 4800 - a; - 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); + day += 7 - fday; + year -= month < 2; + return (year + year / 4 - year / 100 + year / 400 + t[month] + day) % 7; } static bool