~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/calendar.cc

  • Committer: Jay Pipes
  • Date: 2009-02-28 17:49:35 UTC
  • mto: (910.2.6 mordred-noatomics)
  • mto: This revision was merged to the branch mainline in revision 908.
  • Revision ID: jpipes@serialcoder-20090228174935-yfgsw7m0n9gx8pka
Merging in old r903 temporal changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
479
479
 
480
480
  return week_number;
481
481
}
 
482
 
 
483
/**
 
484
 * Takes a number in the form [YY]YYMM and converts it into
 
485
 * a number of months.
 
486
 *
 
487
 * @param Period in the form [YY]YYMM
 
488
 */
 
489
uint32_t year_month_to_months(uint32_t year_month)
 
490
{
 
491
  if (year_month == 0)
 
492
    return 0L;
 
493
 
 
494
  uint32_t years= year_month / 100;
 
495
  if (years < CALENDAR_YY_PART_YEAR)
 
496
    years+= 2000;
 
497
  else if (years < 100)
 
498
    years+= 1900;
 
499
 
 
500
  uint32_t months= year_month % 100;
 
501
  return (years * 12) + (months - 1);
 
502
}
 
503
 
 
504
/**
 
505
 * Takes a number of months and converts it to
 
506
 * a period in the form YYYYMM.
 
507
 *
 
508
 * @param Number of months
 
509
 */
 
510
uint32_t months_to_year_month(uint32_t months)
 
511
{
 
512
  if (months == 0L)
 
513
    return 0L;
 
514
 
 
515
  uint32_t years= (months / 12);
 
516
 
 
517
  if (years < 100)
 
518
    years+= (years < CALENDAR_YY_PART_YEAR) ? 2000 : 1900;
 
519
 
 
520
  return (years * 100) + (months % 12) + 1;
 
521
}