tzfile.h revision 1.8 1 1.8 christos /* $NetBSD: tzfile.h,v 1.8 2015/07/11 16:40:53 christos Exp $ */
2 1.8 christos
3 1.8 christos #ifndef _TZFILE_H_
4 1.8 christos #define _TZFILE_H_
5 1.3 cgd
6 1.1 cgd /*
7 1.8 christos ** This file is in the public domain, so clarified as of
8 1.8 christos ** 1996-06-05 by Arthur David Olson.
9 1.8 christos */
10 1.1 cgd
11 1.8 christos /*
12 1.8 christos ** This header is for use ONLY with the time conversion code.
13 1.8 christos ** There is no guarantee that it will remain unchanged,
14 1.8 christos ** or that it will remain at all.
15 1.8 christos ** Do NOT copy it to any system include directory.
16 1.8 christos ** Thank you!
17 1.8 christos */
18 1.1 cgd
19 1.1 cgd /*
20 1.8 christos ** Information about time zone files.
21 1.8 christos */
22 1.8 christos
23 1.8 christos #ifndef TZDIR /* Time zone object file directory */
24 1.1 cgd #define TZDIR "/usr/share/zoneinfo"
25 1.8 christos #endif /* !defined TZDIR */
26 1.8 christos
27 1.8 christos #ifndef TZDEFAULT
28 1.1 cgd #define TZDEFAULT "/etc/localtime"
29 1.8 christos #endif /* !defined TZDEFAULT */
30 1.8 christos
31 1.8 christos #ifndef TZDEFRULES
32 1.1 cgd #define TZDEFRULES "posixrules"
33 1.8 christos #endif /* !defined TZDEFRULES */
34 1.1 cgd
35 1.1 cgd /*
36 1.1 cgd ** Each file begins with. . .
37 1.1 cgd */
38 1.1 cgd
39 1.8 christos #define TZ_MAGIC "TZif"
40 1.6 kleink
41 1.1 cgd struct tzhead {
42 1.6 kleink char tzh_magic[4]; /* TZ_MAGIC */
43 1.8 christos char tzh_version[1]; /* '\0' or '2' or '3' as of 2013 */
44 1.8 christos char tzh_reserved[15]; /* reserved; must be zero */
45 1.6 kleink char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */
46 1.1 cgd char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */
47 1.1 cgd char tzh_leapcnt[4]; /* coded number of leap seconds */
48 1.1 cgd char tzh_timecnt[4]; /* coded number of transition times */
49 1.1 cgd char tzh_typecnt[4]; /* coded number of local time types */
50 1.1 cgd char tzh_charcnt[4]; /* coded number of abbr. chars */
51 1.1 cgd };
52 1.1 cgd
53 1.1 cgd /*
54 1.1 cgd ** . . .followed by. . .
55 1.1 cgd **
56 1.1 cgd ** tzh_timecnt (char [4])s coded transition times a la time(2)
57 1.1 cgd ** tzh_timecnt (unsigned char)s types of local time starting at above
58 1.1 cgd ** tzh_typecnt repetitions of
59 1.8 christos ** one (char [4]) coded UT offset in seconds
60 1.1 cgd ** one (unsigned char) used to set tm_isdst
61 1.1 cgd ** one (unsigned char) that's an abbreviation list index
62 1.1 cgd ** tzh_charcnt (char)s '\0'-terminated zone abbreviations
63 1.1 cgd ** tzh_leapcnt repetitions of
64 1.1 cgd ** one (char [4]) coded leap second transition times
65 1.1 cgd ** one (char [4]) total correction after above
66 1.8 christos ** tzh_ttisstdcnt (char)s indexed by type; if 1, transition
67 1.8 christos ** time is standard time, if 0,
68 1.1 cgd ** transition time is wall clock time
69 1.1 cgd ** if absent, transition times are
70 1.1 cgd ** assumed to be wall clock time
71 1.8 christos ** tzh_ttisgmtcnt (char)s indexed by type; if 1, transition
72 1.8 christos ** time is UT, if 0,
73 1.8 christos ** transition time is local time
74 1.6 kleink ** if absent, transition times are
75 1.6 kleink ** assumed to be local time
76 1.1 cgd */
77 1.1 cgd
78 1.1 cgd /*
79 1.8 christos ** If tzh_version is '2' or greater, the above is followed by a second instance
80 1.8 christos ** of tzhead and a second instance of the data in which each coded transition
81 1.8 christos ** time uses 8 rather than 4 chars,
82 1.8 christos ** then a POSIX-TZ-environment-variable-style string for use in handling
83 1.8 christos ** instants after the last transition time stored in the file
84 1.8 christos ** (with nothing between the newlines if there is no POSIX representation for
85 1.8 christos ** such instants).
86 1.8 christos **
87 1.8 christos ** If tz_version is '3' or greater, the above is extended as follows.
88 1.8 christos ** First, the POSIX TZ string's hour offset may range from -167
89 1.8 christos ** through 167 as compared to the POSIX-required 0 through 24.
90 1.8 christos ** Second, its DST start time may be January 1 at 00:00 and its stop
91 1.8 christos ** time December 31 at 24:00 plus the difference between DST and
92 1.8 christos ** standard time, indicating DST all year.
93 1.8 christos */
94 1.8 christos
95 1.8 christos /*
96 1.1 cgd ** In the current implementation, "tzset()" refuses to deal with files that
97 1.1 cgd ** exceed any of the limits below.
98 1.1 cgd */
99 1.1 cgd
100 1.8 christos #ifndef TZ_MAX_TIMES
101 1.8 christos #define TZ_MAX_TIMES 2000
102 1.8 christos #endif /* !defined TZ_MAX_TIMES */
103 1.8 christos
104 1.8 christos #ifndef TZ_MAX_TYPES
105 1.8 christos /* This must be at least 17 for Europe/Samara and Europe/Vilnius. */
106 1.8 christos #define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */
107 1.8 christos #endif /* !defined TZ_MAX_TYPES */
108 1.1 cgd
109 1.8 christos #ifndef TZ_MAX_CHARS
110 1.1 cgd #define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */
111 1.8 christos /* (limited by what unsigned chars can hold) */
112 1.8 christos #endif /* !defined TZ_MAX_CHARS */
113 1.1 cgd
114 1.8 christos #ifndef TZ_MAX_LEAPS
115 1.8 christos #define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */
116 1.8 christos #endif /* !defined TZ_MAX_LEAPS */
117 1.1 cgd
118 1.1 cgd #define SECSPERMIN 60
119 1.1 cgd #define MINSPERHOUR 60
120 1.1 cgd #define HOURSPERDAY 24
121 1.1 cgd #define DAYSPERWEEK 7
122 1.1 cgd #define DAYSPERNYEAR 365
123 1.1 cgd #define DAYSPERLYEAR 366
124 1.1 cgd #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)
125 1.8 christos #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
126 1.1 cgd #define MONSPERYEAR 12
127 1.1 cgd
128 1.1 cgd #define TM_SUNDAY 0
129 1.1 cgd #define TM_MONDAY 1
130 1.1 cgd #define TM_TUESDAY 2
131 1.1 cgd #define TM_WEDNESDAY 3
132 1.1 cgd #define TM_THURSDAY 4
133 1.1 cgd #define TM_FRIDAY 5
134 1.1 cgd #define TM_SATURDAY 6
135 1.1 cgd
136 1.1 cgd #define TM_JANUARY 0
137 1.1 cgd #define TM_FEBRUARY 1
138 1.1 cgd #define TM_MARCH 2
139 1.1 cgd #define TM_APRIL 3
140 1.1 cgd #define TM_MAY 4
141 1.1 cgd #define TM_JUNE 5
142 1.1 cgd #define TM_JULY 6
143 1.1 cgd #define TM_AUGUST 7
144 1.1 cgd #define TM_SEPTEMBER 8
145 1.1 cgd #define TM_OCTOBER 9
146 1.1 cgd #define TM_NOVEMBER 10
147 1.1 cgd #define TM_DECEMBER 11
148 1.1 cgd
149 1.1 cgd #define TM_YEAR_BASE 1900
150 1.1 cgd
151 1.1 cgd #define EPOCH_YEAR 1970
152 1.1 cgd #define EPOCH_WDAY TM_THURSDAY
153 1.1 cgd
154 1.8 christos #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
155 1.8 christos
156 1.1 cgd /*
157 1.8 christos ** Since everything in isleap is modulo 400 (or a factor of 400), we know that
158 1.8 christos ** isleap(y) == isleap(y % 400)
159 1.8 christos ** and so
160 1.8 christos ** isleap(a + b) == isleap((a + b) % 400)
161 1.8 christos ** or
162 1.8 christos ** isleap(a + b) == isleap(a % 400 + b % 400)
163 1.8 christos ** This is true even if % means modulo rather than Fortran remainder
164 1.8 christos ** (which is allowed by C89 but not C99).
165 1.8 christos ** We use this to avoid addition overflow problems.
166 1.1 cgd */
167 1.1 cgd
168 1.8 christos #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400)
169 1.1 cgd
170 1.8 christos #endif /* !defined _TZFILE_H_ */
171