48 days_arr[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
54 return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
61 return is_leap(year) ? 366.0 : 365.0;
64 static inline int days(
int year,
int month)
66 if (!(year > 0) && (month > 0 && month < 13))
67 throw Error(malformed_expr,
"Date year or month is bad.");
69 if (month == 2 &&
is_leap(year))
72 return days_arr[month];
89 throw Error(malformed_expr,
"A date's year must be greater the zero.");
90 if (!(month > 0 && month < 13))
91 throw Error(malformed_expr,
92 "A date's month must be between zero and thirteen.");
94 if (!(day > 0 && day <= days(year, month)))
95 throw Error(malformed_expr,
96 "A date's day must be between zero and 28-31, depending on the month.");
100 jdn = (long) year * 367 + month * 275 / 9 - (year + (month > 2)) * 7 / 4
101 - ((year - (month < 3)) / 100 + 1) * 3 / 4 + day + 1721029
L;
122 int *minutes,
double *seconds)
127 double tmp, frac = jd - j;
138 *year = (4
L * j - 1
L) / 146097
L;
139 j = 4
L * j - 1
L - 146097
L * *year;
141 j = (4
L * *day + 3
L) / 1461
L;
142 *day = 4
L * *day + 3
L - 1461
L * j;
143 *day = (*day + 4
L) / 4
L;
144 *month = (5
L * *day - 3
L) / 153
L;
145 *day = 5
L * *day - 3 - 153
L * *month;
146 *day = (*day + 5
L) / 5
L;
147 *year = 100
L * *year + j;
155 tmp = 3600.0 * (frac * 24.0);
156 *hours = (int) (tmp / 3600.0);
157 tmp = tmp - *hours * 3600.0;
158 *minutes = (int) (tmp / 60.0);
159 *seconds = tmp - *minutes * 60.0;
172 throw Error(malformed_expr,
"A date's year must be greater the zero.");
173 if (!(month > 0 && month < 13))
174 throw Error(malformed_expr,
175 "A date's month must be between zero and thirteen.");
177 if (!(day > 0 && day <= days(year, month)))
178 throw Error(malformed_expr,
179 "A date's day must be between zero and 28-31, depending on the month.");
184 ddd += days(year, month);
211 daysInMonth = (
is_leap(year)) ? 29 : 28;
221 throw Error(
"Months must be numbered between 1 and 12 inclusive.");
245 while (ddd > days(year, *month))
246 ddd -= days(year, (*month)++);
int days_in_month(int year, int month)
int dayofweek(double j)
Given a Julian day number, return the day of week for that date.
double days_in_year(int year)
How many days are in the given Gregorian year?
int month_day_to_days(int year, int month, int day)
Given the month and day numbers, return the days since the first of the year.
int is_leap(int year)
Is the given Gregorian year a leap year?
static class NCMLUtil overview
void gregorian_date(double jd, int *year, int *month, int *day, int *hours, int *minutes, double *seconds)
Given a Julian day number, return the Gregorian date.
void days_to_month_day(int year, int ddd, int *month, int *day)
Given the day number of the year, return the month and day of the month.
long julian_day(int year, int month, int day)
Given a gregorian date in year, month and day, return the Julian day number.