Drizzled Public API Documentation

calendar.h
Go to the documentation of this file.
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  * 
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 } /* namespace drizzled */
00340