39
39
#ifndef DRIZZLED_CALENDAR_H
40
40
#define DRIZZLED_CALENDAR_H
42
#define JULIAN_DAY_NUMBER_AT_ABSOLUTE_DAY_ONE INT64_C(1721425)
44
#define DAYS_IN_NORMAL_YEAR INT32_C(365)
45
#define DAYS_IN_LEAP_YEAR INT32_C(366)
47
#define GREGORIAN_START_YEAR 1582
48
#define GREGORIAN_START_MONTH 10
49
#define GREGORIAN_START_DAY 15
51
#define UNIX_EPOCH_MAX_YEARS 2038
52
#define UNIX_EPOCH_MIN_YEARS 1970
54
#define CALENDAR_YY_PART_YEAR 70
57
* The following constants define the system of calculating the number
58
* of days in various periods of time in the Gregorian calendar.
60
* Leap years (years containing 366 days) occur:
62
* - When the year is evenly divisible by 4
63
* - If the year is evenly divisible by 100, it must also
64
* be evenly divisible by 400.
66
#define GREGORIAN_DAYS_IN_400_YEARS UINT32_C(146097)
67
#define GREGORIAN_DAYS_IN_100_YEARS UINT32_C(36524)
68
#define GREGORIAN_DAYS_IN_4_YEARS UINT32_C(1461)
71
* Simple macro returning whether the supplied year
72
* is a leap year in the supplied calendar.
74
* @param Year to evaluate
75
* @param Calendar to use
77
#define IS_LEAP_YEAR(y, c) (days_in_year((y),(c)) == 366)
80
* Simple macro returning whether the supplied year
81
* is a leap year in the Gregorian proleptic calendar.
83
#define IS_GREGORIAN_LEAP_YEAR(y) (days_in_year_gregorian((y)) == 366)
86
* Simple macro returning whether the supplied year
87
* is a leap year in the Julian proleptic calendar.
89
#define IS_JULIAN_LEAP_YEAR(y) (days_in_year_julian((y)) == 366)
122
73
int64_t julian_day_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day);
125
* Translates an absolute day number to a
128
* @param The absolute day number
130
int64_t absolute_day_number_to_julian_day_number(int64_t absolute_day);
133
* Translates a Julian day number to an
134
* absolute day number.
136
* @param The Julian day number
138
int64_t julian_day_number_to_absolute_day_number(int64_t julian_day);
141
77
* Given a supplied Julian Day Number, populates a year, month, and day
152
88
, uint32_t *month_out
153
89
, uint32_t *day_out);
156
* Given a supplied Absolute Day Number, populates a year, month, and day
157
* with the date in the Gregorian Proleptic calendar which corresponds to
158
* the given Absolute Day Number.
160
* @param Absolute Day Number
161
* @param Pointer to year to populate
162
* @param Pointer to month to populate
163
* @param Pointer to the day to populate
165
void gregorian_date_from_absolute_day_number(int64_t absolute_day
167
, uint32_t *month_out
168
, uint32_t *day_out);
171
* Returns the number of days in a particular year.
173
* @param year to evaluate
174
* @param calendar to use
176
uint32_t days_in_year(uint32_t year, enum calendar calendar);
179
* Returns the number of days in a particular Gregorian Proleptic calendar year.
181
* @param year to evaluate
183
uint32_t days_in_year_gregorian(uint32_t year);
186
* Returns the number of days in a particular Julian Proleptic calendar year.
188
* @param year to evaluate
190
uint32_t days_in_year_julian(uint32_t year);
192
#define NUM_LEAP_YEARS(y, c) ((c) == GREGORIAN \
193
? number_of_leap_years_gregorian((y)) \
194
: number_of_leap_years_julian((y)))
197
* Returns the number of leap years that have
198
* occurred in the Julian Proleptic calendar
199
* up to the supplied year.
201
* @param year to evaluate (1 - 9999)
203
int32_t number_of_leap_years_julian(uint32_t year);
206
* Returns the number of leap years that have
207
* occurred in the Gregorian Proleptic calendar
208
* up to the supplied year.
210
* @param year to evaluate (1 - 9999)
212
int32_t number_of_leap_years_gregorian(uint32_t year);
215
94
* Returns the number of days in a month, given
250
129
uint32_t day_of_week(int64_t day_number, bool sunday_is_first_day_of_week);
253
* Given a year, month, and day, returns whether the date is
254
* valid for the Gregorian proleptic calendar.
260
bool is_valid_gregorian_date(uint32_t year, uint32_t month, uint32_t day);
263
132
* Returns whether the supplied date components are within the
264
133
* range of the UNIX epoch.