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)
#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;
{
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;
}