~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/calendar.cc

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

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
53
53
 * Private utility macro for enabling a switch between
54
54
 * Gregorian and Julian leap year date arrays.
55
55
 */
56
 
inline static const uint32_t* days_in_month(uint32_t y, enum calendar c) 
57
 
{
58
 
  if (is_leap_year(y, c))
59
 
    return __leap_days_in_month;
60
 
  else
61
 
    return __normal_days_in_month;
62
 
}
63
 
 
64
 
inline static const uint32_t* days_to_end_month(uint32_t y, enum calendar c) 
65
 
{
66
 
  if (is_leap_year(y, c))
67
 
    return __leap_days_to_end_month;
68
 
  else
69
 
    return __normal_days_to_end_month;
70
 
}
 
56
#define __DAYS_IN_MONTH(y, c) (const uint32_t *) (IS_LEAP_YEAR((y),(c)) ? __leap_days_in_month : __normal_days_in_month)
 
57
#define __DAYS_TO_END_MONTH(y, c) (const uint32_t *) (IS_LEAP_YEAR((y),(c)) ? __leap_days_to_end_month : __normal_days_to_end_month)
71
58
 
72
59
 
73
60
/**
302
289
    return (day <= __normal_days_in_month[month - 1]);
303
290
  else
304
291
  {
305
 
    const uint32_t *p_months= days_in_month(year, (enum calendar) GREGORIAN);
 
292
    const uint32_t *p_months= __DAYS_IN_MONTH(year, (enum calendar) GREGORIAN);
306
293
    return (day <= p_months[1]);
307
294
  }
308
295
}
316
303
 */
317
304
uint32_t days_in_gregorian_year_month(uint32_t year, uint32_t month)
318
305
{
319
 
  const uint32_t *p_months= days_in_month(year, GREGORIAN);
 
306
  const uint32_t *p_months= __DAYS_IN_MONTH(year, GREGORIAN);
320
307
  return p_months[month - 1];
321
308
}
322
309
 
333
320
 * @param Minute
334
321
 * @param Second
335
322
 */
336
 
bool in_unix_epoch_range(uint32_t year,
337
 
                         uint32_t month,
338
 
                         uint32_t day,
339
 
                         uint32_t hour,
340
 
                         uint32_t minute,
341
 
                         uint32_t second)
 
323
bool in_unix_epoch_range(uint32_t year
 
324
                       , uint32_t month
 
325
                       , uint32_t day
 
326
                       , uint32_t hour
 
327
                       , uint32_t minute
 
328
                       , uint32_t second)
342
329
{
343
330
  if (month == 0 || day == 0)
344
331
    return false;
345
 
 
346
332
  if (year < UNIX_EPOCH_MAX_YEARS
347
333
      && year >= UNIX_EPOCH_MIN_YEARS)
348
334
    return true;
349
 
 
350
335
  if (year < UNIX_EPOCH_MIN_YEARS)
351
336
    return false;
352
 
 
353
337
  if (year == UNIX_EPOCH_MAX_YEARS)
354
338
  {
355
339
    if (month > 1)
356
 
    {
357
340
      return false;
358
 
    }
359
341
    if (day > 19)
360
 
    {
361
342
      return false;
362
 
    }
363
343
    else if (day < 19)
364
 
    {
365
344
      return true;
366
 
    }
367
345
    else
368
346
    {
369
347
      /* We are on the final day of UNIX Epoch */