~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/calendar.h

Merge Gustaf - Replaced macros with functions/templates

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
 
 
91
70
namespace drizzled
92
71
{
93
72
 
96
75
 */
97
76
enum calendar
98
77
{
99
 
  GREGORIAN= 1
100
 
, JULIAN= 2
101
 
, HEBREW= 3
102
 
, ISLAM= 4
 
78
  GREGORIAN= 1, 
 
79
  JULIAN= 2, 
 
80
  HEBREW= 3, 
 
81
  ISLAM= 4
103
82
};
104
83
 
 
84
 
105
85
/**
106
86
 * Calculates the Julian Day Number from the year, month 
107
87
 * and day supplied for a Gregorian Proleptic calendar date.
185
165
 */
186
166
uint32_t days_in_year_julian(uint32_t year);
187
167
 
188
 
#define NUM_LEAP_YEARS(y, c) ((c) == GREGORIAN \
189
 
    ? number_of_leap_years_gregorian((y)) \
190
 
    : number_of_leap_years_julian((y)))
191
 
 
192
168
/**
193
169
 * Returns the number of leap years that have
194
170
 * occurred in the Julian Proleptic calendar
216
192
 */
217
193
uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month);
218
194
 
 
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
 
219
202
/**
220
203
 * Returns the number of the day in a week.
221
204
 *
328
311
 */
329
312
uint32_t months_to_year_month(uint32_t months);
330
313
 
 
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
}
 
343
 
331
344
} /* namespace drizzled */
332
345
 
333
346
#endif /* DRIZZLED_CALENDAR_H */