~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/calendar.h

  • Committer: Brian Aker
  • Date: 2010-07-09 17:59:07 UTC
  • Revision ID: brian@gaz-20100709175907-h014kkb6cztsr21d
Fix const_cast, disable the unittest for generators.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 * 
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
44
44
#define DAYS_IN_NORMAL_YEAR INT32_C(365)
45
45
#define DAYS_IN_LEAP_YEAR INT32_C(366)
46
46
 
 
47
#define GREGORIAN_START_YEAR 1582
 
48
#define GREGORIAN_START_MONTH 10
 
49
#define GREGORIAN_START_DAY 15
 
50
 
 
51
#define UNIX_EPOCH_MAX_YEARS 2038
47
52
#define UNIX_EPOCH_MIN_YEARS 1970
48
 
#define UNIX_EPOCH_MAX_YEARS 2038
49
53
 
50
54
#define CALENDAR_YY_PART_YEAR 70
51
55
 
63
67
#define GREGORIAN_DAYS_IN_100_YEARS UINT32_C(36524)
64
68
#define GREGORIAN_DAYS_IN_4_YEARS   UINT32_C(1461)
65
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
 
66
91
namespace drizzled
67
92
{
68
93
 
71
96
 */
72
97
enum calendar
73
98
{
74
 
  GREGORIAN= 1, 
75
 
  JULIAN= 2, 
76
 
  HEBREW= 3, 
77
 
  ISLAM= 4
 
99
  GREGORIAN= 1
 
100
, JULIAN= 2
 
101
, HEBREW= 3
 
102
, ISLAM= 4
78
103
};
79
104
 
80
 
 
81
105
/**
82
106
 * Calculates the Julian Day Number from the year, month 
83
107
 * and day supplied for a Gregorian Proleptic calendar date.
161
185
 */
162
186
uint32_t days_in_year_julian(uint32_t year);
163
187
 
 
188
#define NUM_LEAP_YEARS(y, c) ((c) == GREGORIAN \
 
189
    ? number_of_leap_years_gregorian((y)) \
 
190
    : number_of_leap_years_julian((y)))
 
191
 
164
192
/**
165
193
 * Returns the number of leap years that have
166
194
 * occurred in the Julian Proleptic calendar
188
216
 */
189
217
uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month);
190
218
 
191
 
inline static bool num_leap_years(uint32_t y, enum calendar c) 
192
 
{
193
 
  return (c == GREGORIAN                
194
 
          ? number_of_leap_years_gregorian(y) 
195
 
          : number_of_leap_years_julian(y));
196
 
}
197
 
 
198
219
/**
199
220
 * Returns the number of the day in a week.
200
221
 *
287
308
 * @param Subject year
288
309
 * @param Subject month
289
310
 * @param Subject day
 
311
 * @param Pointer to a uint32_t to hold the resulting year, which 
 
312
 *        may be incremented or decremented depending on flags
290
313
 */
291
314
uint32_t iso_week_number_from_gregorian_date(uint32_t year
292
315
                                           , uint32_t month
293
 
                                           , uint32_t day);
 
316
                                           , uint32_t day
 
317
                                           , uint32_t *year_out);
294
318
/**
295
319
 * Takes a number in the form [YY]YYMM and converts it into
296
320
 * a number of months.
307
331
 */
308
332
uint32_t months_to_year_month(uint32_t months);
309
333
 
310
 
/**
311
 
 * Simple function returning whether the supplied year
312
 
 * is a leap year in the supplied calendar.
313
 
 *
314
 
 * @param Year to evaluate
315
 
 * @param Calendar to use
316
 
 */
317
 
inline static bool is_leap_year(uint32_t y, enum calendar c)
318
 
{
319
 
  return (days_in_year(y, c) == 366);
320
 
}
321
 
 
322
 
/**
323
 
 * Simple function returning whether the supplied year
324
 
 * is a leap year in the Gregorian proleptic calendar.
325
 
 */
326
 
inline static bool is_gregorian_leap_year(uint32_t y)
327
 
{
328
 
  return (days_in_year_gregorian(y) == 366);
329
 
}
330
 
 
331
 
/**
332
 
 * Simple function returning whether the supplied year
333
 
 * is a leap year in the Julian proleptic calendar.
334
 
 */
335
 
inline static bool is_julian_leap_year(uint32_t y) 
336
 
{
337
 
  return (days_in_year_julian(y) == 366);
338
 
}
339
 
 
340
334
} /* namespace drizzled */
341
335
 
342
336
#endif /* DRIZZLED_CALENDAR_H */