fixed some leapyear problems
This commit is contained in:
parent
96a52f7a6f
commit
3824cfd66d
|
@ -8,7 +8,8 @@
|
||||||
static int monthsize[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
static int monthsize[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||||
|
|
||||||
#define SECS_DAY (24*60L*60L)
|
#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 *
|
struct tm *
|
||||||
gmtime(clock)
|
gmtime(clock)
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#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 FIRSTSUNDAY(t) (((t)->tm_yday - (t)->tm_wday + 420) % 7)
|
||||||
#define SUNDAY(day, t) ((day) < 58 ? \
|
|
||||||
((day) < FIRSTSUNDAY(t) ? FIRSTSUNDAY(t) :
|
|
||||||
static int
|
static int
|
||||||
last_sunday(d, t)
|
last_sunday(d, t)
|
||||||
register int d;
|
register int d;
|
||||||
|
@ -16,7 +16,7 @@ last_sunday(d, t)
|
||||||
{
|
{
|
||||||
int first = FIRSTSUNDAY(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;
|
if (d < first) return first;
|
||||||
return d - (d - first) % 7;
|
return d - (d - first) % 7;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue