Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00039 #pragma once
00040
00041 #define JULIAN_DAY_NUMBER_AT_ABSOLUTE_DAY_ONE INT64_C(1721425)
00042
00043 #define DAYS_IN_NORMAL_YEAR INT32_C(365)
00044 #define DAYS_IN_LEAP_YEAR INT32_C(366)
00045
00046 #define UNIX_EPOCH_MIN_YEARS 1970
00047 #define UNIX_EPOCH_MAX_YEARS 2038
00048
00049 #define CALENDAR_YY_PART_YEAR 70
00050
00061 #define GREGORIAN_DAYS_IN_400_YEARS UINT32_C(146097)
00062 #define GREGORIAN_DAYS_IN_100_YEARS UINT32_C(36524)
00063 #define GREGORIAN_DAYS_IN_4_YEARS UINT32_C(1461)
00064
00065 namespace drizzled
00066 {
00067
00071 enum calendar
00072 {
00073 GREGORIAN= 1,
00074 JULIAN= 2,
00075 HEBREW= 3,
00076 ISLAM= 4
00077 };
00078
00079
00093 int64_t julian_day_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day);
00094
00101 int64_t absolute_day_number_to_julian_day_number(int64_t absolute_day);
00102
00109 int64_t julian_day_number_to_absolute_day_number(int64_t julian_day);
00110
00121 void gregorian_date_from_julian_day_number(int64_t julian_day
00122 , uint32_t *year_out
00123 , uint32_t *month_out
00124 , uint32_t *day_out);
00125
00136 void gregorian_date_from_absolute_day_number(int64_t absolute_day
00137 , uint32_t *year_out
00138 , uint32_t *month_out
00139 , uint32_t *day_out);
00140
00147 uint32_t days_in_year(uint32_t year, enum calendar calendar);
00148
00154 uint32_t days_in_year_gregorian(uint32_t year);
00155
00161 uint32_t days_in_year_julian(uint32_t year);
00162
00170 int32_t number_of_leap_years_julian(uint32_t year);
00171
00179 int32_t number_of_leap_years_gregorian(uint32_t year);
00180
00188 uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month);
00189
00190 inline static bool num_leap_years(uint32_t y, enum calendar c)
00191 {
00192 return (c == GREGORIAN
00193 ? number_of_leap_years_gregorian(y)
00194 : number_of_leap_years_julian(y));
00195 }
00196
00224 uint32_t day_of_week(int64_t day_number, bool sunday_is_first_day_of_week);
00225
00234 bool is_valid_gregorian_date(uint32_t year, uint32_t month, uint32_t day);
00235
00249 bool in_unix_epoch_range(uint32_t year
00250 , uint32_t month
00251 , uint32_t day
00252 , uint32_t hour
00253 , uint32_t minute
00254 , uint32_t second);
00255
00269 uint32_t week_number_from_gregorian_date(uint32_t year
00270 , uint32_t month
00271 , uint32_t day
00272 , bool sunday_is_first_day_of_week);
00273
00290 uint32_t iso_week_number_from_gregorian_date(uint32_t year
00291 , uint32_t month
00292 , uint32_t day);
00299 uint32_t year_month_to_months(uint32_t year_month);
00300
00307 uint32_t months_to_year_month(uint32_t months);
00308
00316 inline static bool is_leap_year(uint32_t y, enum calendar c)
00317 {
00318 return (days_in_year(y, c) == 366);
00319 }
00320
00325 inline static bool is_gregorian_leap_year(uint32_t y)
00326 {
00327 return (days_in_year_gregorian(y) == 366);
00328 }
00329
00334 inline static bool is_julian_leap_year(uint32_t y)
00335 {
00336 return (days_in_year_julian(y) == 366);
00337 }
00338
00339 }
00340