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