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