Drizzled Public API Documentation

calendar.h
Go to the documentation of this file.
1 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
39 #pragma once
40 
41 #define JULIAN_DAY_NUMBER_AT_ABSOLUTE_DAY_ONE INT64_C(1721425)
42 
43 #define DAYS_IN_NORMAL_YEAR INT32_C(365)
44 #define DAYS_IN_LEAP_YEAR INT32_C(366)
45 
46 #define UNIX_EPOCH_MIN_YEARS 1970
47 #define UNIX_EPOCH_MAX_YEARS 2038
48 
49 #define CALENDAR_YY_PART_YEAR 70
50 
61 #define GREGORIAN_DAYS_IN_400_YEARS UINT32_C(146097)
62 #define GREGORIAN_DAYS_IN_100_YEARS UINT32_C(36524)
63 #define GREGORIAN_DAYS_IN_4_YEARS UINT32_C(1461)
64 
65 namespace drizzled
66 {
67 
72 {
73  GREGORIAN= 1,
74  JULIAN= 2,
75  HEBREW= 3,
76  ISLAM= 4
77 };
78 
79 
93 int64_t julian_day_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day);
94 
101 int64_t absolute_day_number_to_julian_day_number(int64_t absolute_day);
102 
109 int64_t julian_day_number_to_absolute_day_number(int64_t julian_day);
110 
121 void gregorian_date_from_julian_day_number(int64_t julian_day
122  , uint32_t *year_out
123  , uint32_t *month_out
124  , uint32_t *day_out);
125 
136 void gregorian_date_from_absolute_day_number(int64_t absolute_day
137  , uint32_t *year_out
138  , uint32_t *month_out
139  , uint32_t *day_out);
140 
147 uint32_t days_in_year(uint32_t year, enum calendar calendar);
148 
154 uint32_t days_in_year_gregorian(uint32_t year);
155 
161 uint32_t days_in_year_julian(uint32_t year);
162 
170 int32_t number_of_leap_years_julian(uint32_t year);
171 
179 int32_t number_of_leap_years_gregorian(uint32_t year);
180 
188 uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month);
189 
190 inline static bool num_leap_years(uint32_t y, enum calendar c)
191 {
192  return (c == GREGORIAN
195 }
196 
224 uint32_t day_of_week(int64_t day_number, bool sunday_is_first_day_of_week);
225 
234 bool is_valid_gregorian_date(uint32_t year, uint32_t month, uint32_t day);
235 
249 bool in_unix_epoch_range(uint32_t year
250  , uint32_t month
251  , uint32_t day
252  , uint32_t hour
253  , uint32_t minute
254  , uint32_t second);
255 
269 uint32_t week_number_from_gregorian_date(uint32_t year
270  , uint32_t month
271  , uint32_t day
272  , bool sunday_is_first_day_of_week);
273 
290 uint32_t iso_week_number_from_gregorian_date(uint32_t year
291  , uint32_t month
292  , uint32_t day);
299 uint32_t year_month_to_months(uint32_t year_month);
300 
307 uint32_t months_to_year_month(uint32_t months);
308 
316 inline static bool is_leap_year(uint32_t y, enum calendar c)
317 {
318  return (days_in_year(y, c) == 366);
319 }
320 
325 inline static bool is_gregorian_leap_year(uint32_t y)
326 {
327  return (days_in_year_gregorian(y) == 366);
328 }
329 
334 inline static bool is_julian_leap_year(uint32_t y)
335 {
336  return (days_in_year_julian(y) == 366);
337 }
338 
339 } /* namespace drizzled */
340 
int32_t number_of_leap_years_gregorian(uint32_t year)
uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month)
Definition: calendar.cc:317
bool is_valid_gregorian_date(uint32_t year, uint32_t month, uint32_t day)
Definition: calendar.cc:297
static bool is_leap_year(uint32_t y, enum calendar c)
Definition: calendar.h:316
static bool is_julian_leap_year(uint32_t y)
Definition: calendar.h:334
TODO: Rename this file - func.h is stupid.
uint32_t year_month_to_months(uint32_t year_month)
Definition: calendar.cc:471
int64_t julian_day_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day)
Definition: calendar.cc:101
uint32_t days_in_year_gregorian(const uint32_t year)
Definition: calendar.cc:241
uint32_t months_to_year_month(uint32_t months)
Definition: calendar.cc:492
uint32_t days_in_year_julian(const uint32_t year)
Definition: calendar.cc:230
uint32_t days_in_year(const uint32_t year, enum calendar calendar)
Definition: calendar.cc:218
void gregorian_date_from_absolute_day_number(int64_t absolute_day, uint32_t *year_out, uint32_t *month_out, uint32_t *day_out)
Definition: calendar.cc:185
static bool is_gregorian_leap_year(uint32_t y)
Definition: calendar.h:325
void gregorian_date_from_julian_day_number(int64_t julian_day, uint32_t *year_out, uint32_t *month_out, uint32_t *day_out)
Definition: calendar.cc:148
bool in_unix_epoch_range(uint32_t year, uint32_t month, uint32_t day, uint32_t hour, uint32_t minute, uint32_t second)
Definition: calendar.cc:336
uint32_t iso_week_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day)
Definition: calendar.cc:437
int64_t absolute_day_number_to_julian_day_number(int64_t absolute_day)
Definition: calendar.cc:119
int32_t number_of_leap_years_julian(uint32_t year)
uint32_t day_of_week(int64_t day_number, bool sunday_is_first_day_of_week)
Definition: calendar.cc:279
uint32_t week_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day, bool sunday_is_first_day_of_week)
Definition: calendar.cc:394
int64_t julian_day_number_to_absolute_day_number(int64_t julian_day)
Definition: calendar.cc:131