~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/calendar.h

  • Committer: Brian Aker
  • Date: 2010-03-31 19:14:14 UTC
  • Revision ID: brian@gaz-20100331191414-9yv44mmpvf0tb7l1
Updated to use show schemas specific table.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
#define GREGORIAN_DAYS_IN_100_YEARS UINT32_C(36524)
68
68
#define GREGORIAN_DAYS_IN_4_YEARS   UINT32_C(1461)
69
69
 
 
70
/**
 
71
 * Simple macro returning whether the supplied year
 
72
 * is a leap year in the supplied calendar.
 
73
 *
 
74
 * @param Year to evaluate
 
75
 * @param Calendar to use
 
76
 */
 
77
#define IS_LEAP_YEAR(y, c) (days_in_year((y),(c)) == 366)
 
78
 
 
79
/**
 
80
 * Simple macro returning whether the supplied year
 
81
 * is a leap year in the Gregorian proleptic calendar.
 
82
 */
 
83
#define IS_GREGORIAN_LEAP_YEAR(y) (days_in_year_gregorian((y)) == 366)
 
84
 
 
85
/**
 
86
 * Simple macro returning whether the supplied year
 
87
 * is a leap year in the Julian proleptic calendar.
 
88
 */
 
89
#define IS_JULIAN_LEAP_YEAR(y) (days_in_year_julian((y)) == 366)
 
90
 
70
91
namespace drizzled
71
92
{
72
93
 
 
94
#ifdef __cplusplus
 
95
extern "C" {
 
96
#endif
 
97
 
73
98
/**
74
99
 * Different calendars supported by the temporal library
75
100
 */
76
101
enum calendar
77
102
{
78
 
  GREGORIAN= 1, 
79
 
  JULIAN= 2, 
80
 
  HEBREW= 3, 
81
 
  ISLAM= 4
 
103
  GREGORIAN= 1
 
104
, JULIAN= 2
 
105
, HEBREW= 3
 
106
, ISLAM= 4
82
107
};
83
108
 
84
 
 
85
109
/**
86
110
 * Calculates the Julian Day Number from the year, month 
87
111
 * and day supplied for a Gregorian Proleptic calendar date.
165
189
 */
166
190
uint32_t days_in_year_julian(uint32_t year);
167
191
 
 
192
#define NUM_LEAP_YEARS(y, c) ((c) == GREGORIAN \
 
193
    ? number_of_leap_years_gregorian((y)) \
 
194
    : number_of_leap_years_julian((y)))
 
195
 
168
196
/**
169
197
 * Returns the number of leap years that have
170
198
 * occurred in the Julian Proleptic calendar
192
220
 */
193
221
uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month);
194
222
 
195
 
inline static bool num_leap_years(uint32_t y, enum calendar c) 
196
 
{
197
 
  return (c == GREGORIAN                
198
 
          ? number_of_leap_years_gregorian(y) 
199
 
          : number_of_leap_years_julian(y));
200
 
}
201
 
 
202
223
/**
203
224
 * Returns the number of the day in a week.
204
225
 *
291
312
 * @param Subject year
292
313
 * @param Subject month
293
314
 * @param Subject day
 
315
 * @param Pointer to a uint32_t to hold the resulting year, which 
 
316
 *        may be incremented or decremented depending on flags
294
317
 */
295
318
uint32_t iso_week_number_from_gregorian_date(uint32_t year
296
319
                                           , uint32_t month
297
 
                                           , uint32_t day);
 
320
                                           , uint32_t day
 
321
                                           , uint32_t *year_out);
298
322
/**
299
323
 * Takes a number in the form [YY]YYMM and converts it into
300
324
 * a number of months.
311
335
 */
312
336
uint32_t months_to_year_month(uint32_t months);
313
337
 
314
 
/**
315
 
 * Simple function returning whether the supplied year
316
 
 * is a leap year in the supplied calendar.
317
 
 *
318
 
 * @param Year to evaluate
319
 
 * @param Calendar to use
320
 
 */
321
 
inline static bool is_leap_year(uint32_t y, enum calendar c)
322
 
{
323
 
  return (days_in_year(y, c) == 366);
324
 
}
325
 
 
326
 
/**
327
 
 * Simple function returning whether the supplied year
328
 
 * is a leap year in the Gregorian proleptic calendar.
329
 
 */
330
 
inline static bool is_gregorian_leap_year(uint32_t y)
331
 
{
332
 
  return (days_in_year_gregorian(y) == 366);
333
 
}
334
 
 
335
 
/**
336
 
 * Simple function returning whether the supplied year
337
 
 * is a leap year in the Julian proleptic calendar.
338
 
 */
339
 
inline static bool is_julian_leap_year(uint32_t y) 
340
 
{
341
 
  return (days_in_year_julian(y) == 366);
342
 
}
 
338
#ifdef __cplusplus
 
339
}
 
340
#endif
343
341
 
344
342
} /* namespace drizzled */
345
343