~drizzle-pbxt/drizzle/drizzle-pbxt-2

« back to all changes in this revision

Viewing changes to drizzled/calendar.cc

  • Committer: Paul McCullagh
  • Date: 2009-11-10 14:18:39 UTC
  • mfrom: (1038.1.7 drizzle-pbxt-pre-merge)
  • Revision ID: paul.mccullagh@primebase.org-20091110141839-2j3k43b17ag6f605
Merged Drizzle trunk and PBXT 1.0.09

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#define __DAYS_IN_MONTH(y, c) (const uint32_t *) (IS_LEAP_YEAR((y),(c)) ? __leap_days_in_month : __normal_days_in_month)
41
41
#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)
42
42
 
43
 
/**
44
 
 * Calculates the Julian Day Number from the year, month 
45
 
 * and day at noon supplied in the Julian calendar.
46
 
 *
47
 
 * The following formula is used to calculate the Julian
48
 
 * Day Number from a date in the Julian Calendar.
49
 
 *
50
 
 * The months January to December are 1 to 12. 
51
 
 * Astronomical year numbering is used, thus 1 BC is 0, 2 BC is −1, 
52
 
 * and 4713 BC is −4712. In all divisions (except for JD) the floor 
53
 
 * function is applied to the quotient (for dates since 
54
 
 * March 1, −4800 all quotients are non-negative, so we can also 
55
 
 * apply truncation).
56
 
 *
57
 
 * a = (14 - month) / 12
58
 
 * y = year + 4800 - a
59
 
 * m = month + 12a - 3
60
 
 * JDN = day + ((153m + 2) / 5) + 365y + (y / 4) - 32083
61
 
 *
62
 
 * @cite http://en.wikipedia.org/wiki/Julian_day#Calculation
63
 
 *
64
 
 * @note
65
 
 *
66
 
 * Year month and day values are assumed to be valid.  This 
67
 
 * method does no bounds checking or validation.
68
 
 *
69
 
 * @param Year of date
70
 
 * @param Month of date
71
 
 * @param Day of date
72
 
 */
73
 
int64_t julian_day_number_from_julian_date(uint32_t year, uint32_t month, uint32_t day)
74
 
{
75
 
  int64_t day_number;
76
 
  int64_t a= (14 - month) / 12;
77
 
  int64_t y= year + 4800 - a;
78
 
  int64_t m= month + (12 * a) - 3;
79
 
 
80
 
  day_number= day + (((153 * m) + 2) / 5) + (365 * y) + (y / 4) - 32083;
81
 
  return day_number;
82
 
}
83
43
 
84
44
/**
85
45
 * Calculates the Julian Day Number from the year, month