41
41
#include "drizzled/calendar.h"
47
#define JULIAN_DAY_NUMBER_AT_ABSOLUTE_DAY_ONE INT64_C(1721425)
49
#define UNIX_EPOCH_MAX_YEARS 2038
50
#define UNIX_EPOCH_MIN_YEARS 1970
52
#define CALENDAR_YY_PART_YEAR 70
55
* Simple macro returning whether the supplied year
56
* is a leap year in the supplied calendar.
58
* @param Year to evaluate
59
* @param Calendar to use
61
#define IS_LEAP_YEAR(y, c) (days_in_year((y),(c)) == 366)
46
63
/** Static arrays for number of days in a month and their "day ends" */
47
64
static const uint32_t __leap_days_in_month[12]= {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
48
65
static const uint32_t __normal_days_in_month[12]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
49
66
static const uint32_t __leap_days_to_end_month[13]= {0, 31, 60, 91, 121, 151, 182, 213, 244, 274, 305, 335, 366};
50
67
static const uint32_t __normal_days_to_end_month[13]= {0, 31, 59, 90, 120, 150, 181, 212, 243, 273, 304, 334, 365};
70
* Returns the number of days in a particular year.
72
* @param year to evaluate
73
* @param calendar to use
75
static inline uint32_t days_in_year(uint32_t year, enum calendar calendar);
78
* Returns the number of days in a particular Gregorian Proleptic calendar year.
80
* @param year to evaluate
82
static inline uint32_t days_in_year_gregorian(uint32_t year);
85
* Returns the number of days in a particular Julian Proleptic calendar year.
87
* @param year to evaluate
89
static inline uint32_t days_in_year_julian(uint32_t year);
91
static inline int64_t absolute_day_number_to_julian_day_number(int64_t absolute_day);
53
94
* Private utility macro for enabling a switch between
54
95
* Gregorian and Julian leap year date arrays.
100
* Translates an absolute day number to a
101
* Julian day number. Note that a Julian day number
102
* is not the same as a date in the Julian proleptic calendar.
104
* @param The absolute day number
106
int64_t absolute_day_number_to_julian_day_number(int64_t absolute_day)
108
return absolute_day + JULIAN_DAY_NUMBER_AT_ABSOLUTE_DAY_ONE;
112
* Translates a Julian day number to an
113
* absolute day number. Note that a Julian day number
114
* is not the same as a date in the Julian proleptic calendar.
116
* @param The Julian day number
118
int64_t julian_day_number_to_absolute_day_number(int64_t julian_day)
120
return julian_day - JULIAN_DAY_NUMBER_AT_ABSOLUTE_DAY_ONE;
124
141
* Given a supplied Julian Day Number, populates a year, month, and day
125
142
* with the date in the Gregorian Proleptic calendar which corresponds to
126
143
* the given Julian Day Number.
180
* Translates an absolute day number to a
181
* Julian day number. Note that a Julian day number
182
* is not the same as a date in the Julian proleptic calendar.
184
* @param The absolute day number
186
inline int64_t absolute_day_number_to_julian_day_number(int64_t absolute_day)
188
return absolute_day + JULIAN_DAY_NUMBER_AT_ABSOLUTE_DAY_ONE;
163
192
* Given a supplied Absolute Day Number, populates a year, month, and day
164
193
* with the date in the Gregorian Proleptic calendar which corresponds to
165
194
* the given Absolute Day Number.
277
* Given a year, month, and day, returns whether the date is
278
* valid for the Gregorian proleptic calendar.
284
bool is_valid_gregorian_date(uint32_t year, uint32_t month, uint32_t day)
289
return (day <= __normal_days_in_month[month - 1]);
292
const uint32_t *p_months= __DAYS_IN_MONTH(year, (enum calendar) GREGORIAN);
293
return (day <= p_months[1]);
298
306
* Returns the number of days in a month, given
299
307
* a year and a month in the Gregorian calendar.