fixed some leapyear problems
authorceriel <none@none>
Mon, 19 Jun 1989 09:50:38 +0000 (09:50 +0000)
committerceriel <none@none>
Mon, 19 Jun 1989 09:50:38 +0000 (09:50 +0000)
lang/cem/libcc/gen/gmtime.c
lang/cem/libcc/gen/localtime.c

index acb7f43..5944ccd 100644 (file)
@@ -8,7 +8,8 @@
 static int monthsize[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 
 #define SECS_DAY (24*60L*60L)
-#define YEARSIZE(year) ((year) % 4 ? 365 : 366)
+#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
+#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
 
 struct tm *
 gmtime(clock)
index b4dcc8a..ee150b0 100644 (file)
@@ -5,10 +5,10 @@
 #include <time.h>
 #endif
 
-#define YEARSIZE(year) ((year) % 4 ? 365 : 366)
+#define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
+#define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
 #define FIRSTSUNDAY(t) (((t)->tm_yday - (t)->tm_wday + 420) % 7)
-#define SUNDAY(day, t) ((day) < 58 ? \
-                         ((day) < FIRSTSUNDAY(t) ? FIRSTSUNDAY(t) :
+
 static int
 last_sunday(d, t)
        register int d;
@@ -16,7 +16,7 @@ last_sunday(d, t)
 {
        int first = FIRSTSUNDAY(t);
 
-       if (d >= 58 && YEARSIZE(t->tm_year)) d++;
+       if (d >= 58 && LEAPYEAR(t->tm_year+1900)) d++;
        if (d < first) return first;
        return d - (d - first) % 7;
 }