Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ntp / include / ntp_calendar.h
blob48690c6fc1f5f26ed2c4ab195a7f58ab88e0a9ef
1 /* $NetBSD$ */
3 /*
4 * ntp_calendar.h - definitions for the calendar time-of-day routine
5 */
6 #ifndef NTP_CALENDAR_H
7 #define NTP_CALENDAR_H
9 #include "ntp_types.h"
11 struct calendar {
12 u_short year; /* year (A.D.) */
13 u_short yearday; /* day of year, 1 = January 1 */
14 u_char month; /* month, 1 = January */
15 u_char monthday; /* day of month */
16 u_char hour; /* hour of day, midnight = 0 */
17 u_char minute; /* minute of hour */
18 u_char second; /* second of minute */
22 * Days in each month. 30 days hath September...
24 #define JAN 31
25 #define FEB 28
26 #define FEBLEAP 29
27 #define MAR 31
28 #define APR 30
29 #define MAY 31
30 #define JUN 30
31 #define JUL 31
32 #define AUG 31
33 #define SEP 30
34 #define OCT 31
35 #define NOV 30
36 #define DEC 31
39 * We deal in a 4 year cycle starting at March 1, 1900. We assume
40 * we will only want to deal with dates since then, and not to exceed
41 * the rollover day in 2036.
43 #define SECSPERMIN (60) /* seconds per minute */
44 #define MINSPERHR (60) /* minutes per hour */
45 #define HRSPERDAY (24) /* hours per day */
46 #define DAYSPERYEAR (365) /* days per year */
48 #define SECSPERDAY (SECSPERMIN*MINSPERHR*HRSPERDAY)
49 #define SECSPERYEAR (365 * SECSPERDAY) /* regular year */
50 #define SECSPERLEAPYEAR (366 * SECSPERDAY) /* leap year */
52 #define MAR1900 ((JAN+FEB) * SECSPERDAY) /* no leap year in 1900 */
53 #define DAYSPERCYCLE (365+365+365+366) /* 3 normal years plus leap */
54 #define SECSPERCYCLE (DAYSPERCYCLE*SECSPERDAY)
55 #define YEARSPERCYCLE 4
58 * Gross hacks. I have illicit knowlege that there won't be overflows
59 * here, the compiler often can't tell this.
61 #define TIMES60(val) ((((val)<<4) - (val))<<2) /* *(16 - 1) * 4 */
62 #define TIMES24(val) (((val)<<4) + ((val)<<3)) /* *16 + *8 */
63 #define TIMES7(val) (((val)<<3) - (val)) /* *8 - *1 */
64 #define TIMESDPERC(val) (((val)<<10) + ((val)<<8) \
65 + ((val)<<7) + ((val)<<5) \
66 + ((val)<<4) + ((val)<<2) + (val)) /* *big* hack */
69 * Another big hack. Cycle 22 started on March 1, 1988. This is
70 * STARTCYCLE22 seconds after the start of cycle 0.
72 #define CYCLE22 (22)
73 #define STARTCYCLE22 (u_long)(0xa586b500) /* 2777068800 */
74 #define MAR1988 (u_long)(STARTCYCLE22 + (u_long)MAR1900)
77 * The length of January + February in leap and non-leap years.
79 #define JANFEBNOLEAP ((JAN+FEB) * SECSPERDAY)
80 #define JANFEBLEAP ((JAN+FEBLEAP) * SECSPERDAY)
83 extern void caljulian P((u_long, struct calendar *));
84 extern u_long caltontp P((const struct calendar *));
87 * Additional support stuff for Ed Rheingold's calendrical calculations
91 * Start day of NTP time as days past the imaginary date 12/1/1 BC.
92 * P((This is the beginning of the Christian Era, or BCE.))
94 #define DAY_NTP_STARTS 693596
96 * The Gregorian calendar is based on a 400 year cycle. This is the number
97 * of days in each cycle.
99 #define GREGORIAN_CYCLE_DAYS 146097
102 * Days in a normal 100 year leap year calendar. We lose a leap year day
103 * in years evenly divisible by 100 but not by 400.
105 #define GREGORIAN_NORMAL_CENTURY_DAYS 36524
108 * Days in a normal 4 year leap year calendar cycle.
110 #define GREGORIAN_NORMAL_LEAP_CYCLE_DAYS 1461
112 #define is_leapyear(y) (y%4 == 0 && !(y%100 == 0 && !(y%400 == 0)))
114 #endif