[hackers] [sbase] fixed incorrect fday handling in dayofweek() function || Willem van de Krol

From: <git_AT_suckless.org>
Date: Fri, 04 Jul 2014 22:47:40 +0200

commit f02f2190f064584ff838352a8ec1cc92dc191742
Author: Willem van de Krol <008054_AT_jfc.nl>
Date: Fri Jul 4 22:23:52 2014 +0200

    fixed incorrect fday handling in dayofweek() function

diff --git a/cal.c b/cal.c
index 8faf3de..a477db9 100644
--- a/cal.c
+++ b/cal.c
_AT_@ -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;
-
- 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);
+ static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
+
+ day += 7 - fday;
+ year -= month < 2;
+ return (year + year / 4 - year / 100 + year / 400 + t[month] + day) % 7;
 }
 
 static bool
Received on Fri Jul 04 2014 - 22:47:40 CEST

This archive was generated by hypermail 2.3.0 : Fri Jul 04 2014 - 22:48:09 CEST