1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
const char month_days[] = { 0, 3, 3, 6, 8, 11, 13, 16, 19, 21, 24, 26, 29, };
int is_leap_year(int y){
return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}
int days_in_month(int year, int month){
if (month == 2)
return 28 + is_leap_year(year);
return 28 + month_days[month] - month_days[month - 1];
}
int days_since_january_first(int year, int month, int day){
month--;
return month * 28 + month_days[month] +
is_leap_year(year) * (month > 1) +
day - 1;
return ret;
}
|