1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
typedef struct {
int mDay, mMon, mYear;
};
#define isleap(y) ((y) % 4 == 0 && ((y) % 100 || (y) % 400 == 0))
static const int daytabs[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
};
Date *setdate(Date *p, int day, int mon, int year)
{
return set(p, day, mon, year);
}
Date *setToday(Date *p)
{
time_t timer = time(NULL);
struct tm *tp = localtime(&timer);
return set(p, tp->tm_mday, tp->tm_mon + 1, tp->tm_year + 1900);
}
static Date *set(Date *p, int d, int m, int y)
{
if (!isValidDate(d, m, y)){
cout << "gecersiz tarih : " << d << m << y << endl;
exit(EXIT_FAILURE);
}
p->mDay = d;
p->mMon = m;
p->mYear = y;
return p;
}
|