~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/calendar.cc

  • Committer: LinuxJedi
  • Date: 2010-09-09 06:14:45 UTC
  • mto: (1750.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1751.
  • Revision ID: linuxjedi@linuxjedi-laptop-20100909061445-1jz91d5eed932616
Fix another wrong header, grr...

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
427
414
 */
428
415
uint32_t iso_week_number_from_gregorian_date(uint32_t year
429
416
                                           , uint32_t month
430
 
                                           , uint32_t day)
 
417
                                           , uint32_t day
 
418
                                           , uint32_t *year_out)
431
419
{
432
420
  struct tm broken_time;
433
421
 
 
422
  if (year_out != NULL)
 
423
    *year_out= year;
 
424
 
434
425
  broken_time.tm_year= year;
435
426
  broken_time.tm_mon= month - 1; /* struct tm has non-ordinal months */
436
427
  broken_time.tm_mday= day;
450
441
 
451
442
  uint32_t week_number= (uint32_t) atoi(result);
452
443
 
 
444
  /* 
 
445
   * ISO8601:1988 states that if the first week in January
 
446
   * does not contain 4 days, then the resulting week number
 
447
   * shall be 52 or 53, depending on the number of days in the
 
448
   * previous year.  In this case, we adjust the outbound
 
449
   * year parameter down a year.
 
450
   */
 
451
  if (year_out != NULL)
 
452
    if (week_number == 53 || week_number == 52)
 
453
      if (month == 1)
 
454
        *year_out--;
 
455
 
453
456
  return week_number;
454
457
}
455
458