~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/calendar.h

  • Committer: Monty Taylor
  • Date: 2010-09-16 23:12:30 UTC
  • mto: (1775.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1773.
  • Revision ID: mordred@inaugust.com-20100916231230-uchkqks21rwzbmpz
Include files in tarball that were being left out.

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
48
48
#define GREGORIAN_START_MONTH 10
49
49
#define GREGORIAN_START_DAY 15
50
50
 
 
51
#define UNIX_EPOCH_MAX_YEARS 2038
51
52
#define UNIX_EPOCH_MIN_YEARS 1970
52
 
#define UNIX_EPOCH_MAX_YEARS 2038
53
53
 
54
54
#define CALENDAR_YY_PART_YEAR 70
55
55
 
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
 
75
96
 */
76
97
enum calendar
77
98
{
78
 
  GREGORIAN= 1, 
79
 
  JULIAN= 2, 
80
 
  HEBREW= 3, 
81
 
  ISLAM= 4
 
99
  GREGORIAN= 1
 
100
, JULIAN= 2
 
101
, HEBREW= 3
 
102
, ISLAM= 4
82
103
};
83
104
 
84
 
 
85
105
/**
86
106
 * Calculates the Julian Day Number from the year, month 
87
107
 * and day supplied for a Gregorian Proleptic calendar date.
165
185
 */
166
186
uint32_t days_in_year_julian(uint32_t year);
167
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
 
168
192
/**
169
193
 * Returns the number of leap years that have
170
194
 * occurred in the Julian Proleptic calendar
192
216
 */
193
217
uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month);
194
218
 
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
219
/**
203
220
 * Returns the number of the day in a week.
204
221
 *
291
308
 * @param Subject year
292
309
 * @param Subject month
293
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
294
313
 */
295
314
uint32_t iso_week_number_from_gregorian_date(uint32_t year
296
315
                                           , uint32_t month
297
 
                                           , uint32_t day);
 
316
                                           , uint32_t day
 
317
                                           , uint32_t *year_out);
298
318
/**
299
319
 * Takes a number in the form [YY]YYMM and converts it into
300
320
 * a number of months.
311
331
 */
312
332
uint32_t months_to_year_month(uint32_t months);
313
333
 
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
 
 
344
334
} /* namespace drizzled */
345
335
 
346
336
#endif /* DRIZZLED_CALENDAR_H */