drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
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
38
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
65namespace drizzled
66{
67
72{
73 GREGORIAN= 1,
74 JULIAN= 2,
75 HEBREW= 3,
76 ISLAM= 4
77};
78
79
93int64_t julian_day_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day);
94
101int64_t absolute_day_number_to_julian_day_number(int64_t absolute_day);
102
109int64_t julian_day_number_to_absolute_day_number(int64_t julian_day);
110
121void 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
136void 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
147uint32_t days_in_year(uint32_t year, enum calendar calendar);
148
154uint32_t days_in_year_gregorian(uint32_t year);
155
161uint32_t days_in_year_julian(uint32_t year);
162
170int32_t number_of_leap_years_julian(uint32_t year);
171
179int32_t number_of_leap_years_gregorian(uint32_t year);
180
188uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month);
189
190inline static bool num_leap_years(uint32_t y, enum calendar c)
191{
192 return (c == GREGORIAN
195}
196
224uint32_t day_of_week(int64_t day_number, bool sunday_is_first_day_of_week);
225
234bool is_valid_gregorian_date(uint32_t year, uint32_t month, uint32_t day);
235
249bool 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
269uint32_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
290uint32_t iso_week_number_from_gregorian_date(uint32_t year
291 , uint32_t month
292 , uint32_t day);
299uint32_t year_month_to_months(uint32_t year_month);
300
307uint32_t months_to_year_month(uint32_t months);
308
316inline static bool is_leap_year(uint32_t y, enum calendar c)
317{
318 return (days_in_year(y, c) == 366);
319}
320
325inline static bool is_gregorian_leap_year(uint32_t y)
326{
327 return (days_in_year_gregorian(y) == 366);
328}
329
334inline static bool is_julian_leap_year(uint32_t y)
335{
336 return (days_in_year_julian(y) == 366);
337}
338
339} /* namespace drizzled */
340
TODO: Rename this file - func.h is stupid.
int64_t absolute_day_number_to_julian_day_number(int64_t absolute_day)
Definition calendar.cc:111
uint32_t iso_week_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day)
Definition calendar.cc:429
uint32_t days_in_year_julian(const uint32_t year)
Definition calendar.cc:222
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:140
uint32_t months_to_year_month(uint32_t months)
Definition calendar.cc:484
bool is_valid_gregorian_date(uint32_t year, uint32_t month, uint32_t day)
Definition calendar.cc:289
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:386
int64_t julian_day_number_from_gregorian_date(uint32_t year, uint32_t month, uint32_t day)
Definition calendar.cc:93
uint32_t days_in_year_gregorian(const uint32_t year)
Definition calendar.cc:233
uint32_t year_month_to_months(uint32_t year_month)
Definition calendar.cc:463
static bool is_leap_year(uint32_t y, enum calendar c)
Definition calendar.h:316
uint32_t day_of_week(int64_t day_number, bool sunday_is_first_day_of_week)
Definition calendar.cc:271
uint32_t days_in_year(const uint32_t year, enum calendar calendar)
Definition calendar.cc:210
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:309
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:177
int32_t number_of_leap_years_julian(uint32_t year)
static bool is_gregorian_leap_year(uint32_t y)
Definition calendar.h:325
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:328
int64_t julian_day_number_to_absolute_day_number(int64_t julian_day)
Definition calendar.cc:123
static bool is_julian_leap_year(uint32_t y)
Definition calendar.h:334