diff --git a/lang/cem/libcc/gen/gmtime.c b/lang/cem/libcc/gen/gmtime.c index acb7f43a0..5944ccdf7 100644 --- a/lang/cem/libcc/gen/gmtime.c +++ b/lang/cem/libcc/gen/gmtime.c @@ -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) diff --git a/lang/cem/libcc/gen/localtime.c b/lang/cem/libcc/gen/localtime.c index b4dcc8a24..ee150b09a 100644 --- a/lang/cem/libcc/gen/localtime.c +++ b/lang/cem/libcc/gen/localtime.c @@ -5,10 +5,10 @@ #include #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; }