2 * ntp_calendar.h - definitions for the calendar time-of-day routine
10 u_short year; /* year (A.D.) */
11 u_short yearday; /* day of year, 1 = January 1 */
12 u_char month; /* month, 1 = January */
13 u_char monthday; /* day of month */
14 u_char hour; /* hour of day, midnight = 0 */
15 u_char minute; /* minute of hour */
16 u_char second; /* second of minute */
20 * Days in each month. 30 days hath September...
37 * We deal in a 4 year cycle starting at March 1, 1900. We assume
38 * we will only want to deal with dates since then, and not to exceed
39 * the rollover day in 2036.
41 #define SECSPERMIN (60) /* seconds per minute */
42 #define MINSPERHR (60) /* minutes per hour */
43 #define HRSPERDAY (24) /* hours per day */
44 #define DAYSPERYEAR (365) /* days per year */
46 #define SECSPERDAY (SECSPERMIN*MINSPERHR*HRSPERDAY)
47 #define SECSPERYEAR (365 * SECSPERDAY) /* regular year */
48 #define SECSPERLEAPYEAR (366 * SECSPERDAY) /* leap year */
50 #define MAR1900 ((JAN+FEB) * SECSPERDAY) /* no leap year in 1900 */
51 #define DAYSPERCYCLE (365+365+365+366) /* 3 normal years plus leap */
52 #define SECSPERCYCLE (DAYSPERCYCLE*SECSPERDAY)
53 #define YEARSPERCYCLE 4
56 * Gross hacks. I have illicit knowlege that there won't be overflows
57 * here, the compiler often can't tell this.
59 #define TIMES60(val) ((((val)<<4) - (val))<<2) /* *(16 - 1) * 4 */
60 #define TIMES24(val) (((val)<<4) + ((val)<<3)) /* *16 + *8 */
61 #define TIMES7(val) (((val)<<3) - (val)) /* *8 - *1 */
62 #define TIMESDPERC(val) (((val)<<10) + ((val)<<8) \
63 + ((val)<<7) + ((val)<<5) \
64 + ((val)<<4) + ((val)<<2) + (val)) /* *big* hack */
67 * Another big hack. Cycle 22 started on March 1, 1988. This is
68 * STARTCYCLE22 seconds after the start of cycle 0.
71 #define STARTCYCLE22 (u_long)(0xa586b500) /* 2777068800 */
72 #define MAR1988 (u_long)(STARTCYCLE22 + (u_long)MAR1900)
75 * The length of January + February in leap and non-leap years.
77 #define JANFEBNOLEAP ((JAN+FEB) * SECSPERDAY)
78 #define JANFEBLEAP ((JAN+FEBLEAP) * SECSPERDAY)
81 extern void caljulian P((u_long, struct calendar *));
82 extern u_long caltontp P((const struct calendar *));
85 * Additional support stuff for Ed Rheingold's calendrical calculations
89 * Start day of NTP time as days past the imaginary date 12/1/1 BC.
90 * P((This is the beginning of the Christian Era, or BCE.))
92 #define DAY_NTP_STARTS 693596
94 * The Gregorian calendar is based on a 400 year cycle. This is the number
95 * of days in each cycle.
97 #define GREGORIAN_CYCLE_DAYS 146097
100 * Days in a normal 100 year leap year calendar. We lose a leap year day
101 * in years evenly divisible by 100 but not by 400.
103 #define GREGORIAN_NORMAL_CENTURY_DAYS 36524
106 * Days in a normal 4 year leap year calendar cycle.
108 #define GREGORIAN_NORMAL_LEAP_CYCLE_DAYS 1461
110 #define is_leapyear(y) (y%4 == 0 && !(y%100 == 0 && !(y%400 == 0)))