1 1.14 christos /* $NetBSD: tzfile.h,v 1.14 2025/01/31 18:23: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.11 christos # define TZDIR "/usr/share/zoneinfo" 25 1.8 christos #endif /* !defined TZDIR */ 26 1.8 christos 27 1.8 christos #ifndef TZDEFAULT 28 1.11 christos # define TZDEFAULT "/etc/localtime" 29 1.8 christos #endif /* !defined TZDEFAULT */ 30 1.8 christos 31 1.8 christos #ifndef TZDEFRULES 32 1.11 christos # define TZDEFRULES "posixrules" 33 1.8 christos #endif /* !defined TZDEFRULES */ 34 1.1 cgd 35 1.9 christos 36 1.14 christos /* See Internet RFC 9636 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.10 christos char tzh_ttisutcnt[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.10 christos ** transition time is local (wall clock) 72 1.10 christos ** time; if absent, transition times are 73 1.6 kleink ** assumed to be local time 74 1.10 christos ** tzh_ttisutcnt (char)s indexed by type; if 1, transition 75 1.10 christos ** time is UT, if 0, transition time is 76 1.10 christos ** local time; if absent, transition 77 1.10 christos ** times are assumed to be local time. 78 1.10 christos ** When this is 1, the corresponding 79 1.10 christos ** std/wall indicator must also be 1. 80 1.1 cgd */ 81 1.1 cgd 82 1.1 cgd /* 83 1.8 christos ** If tzh_version is '2' or greater, the above is followed by a second instance 84 1.8 christos ** of tzhead and a second instance of the data in which each coded transition 85 1.8 christos ** time uses 8 rather than 4 chars, 86 1.8 christos ** then a POSIX-TZ-environment-variable-style string for use in handling 87 1.8 christos ** instants after the last transition time stored in the file 88 1.13 christos ** (with nothing between the newlines if there is no POSIX.1-2017 89 1.13 christos ** representation for such instants). 90 1.8 christos ** 91 1.8 christos ** If tz_version is '3' or greater, the above is extended as follows. 92 1.13 christos ** First, the TZ string's hour offset may range from -167 93 1.8 christos ** through 167 as compared to the POSIX-required 0 through 24. 94 1.8 christos ** Second, its DST start time may be January 1 at 00:00 and its stop 95 1.8 christos ** time December 31 at 24:00 plus the difference between DST and 96 1.8 christos ** standard time, indicating DST all year. 97 1.8 christos */ 98 1.8 christos 99 1.8 christos /* 100 1.1 cgd ** In the current implementation, "tzset()" refuses to deal with files that 101 1.1 cgd ** exceed any of the limits below. 102 1.1 cgd */ 103 1.1 cgd 104 1.8 christos #ifndef TZ_MAX_TIMES 105 1.12 christos /* This must be at least 242 for Europe/London with 'zic -b fat'. */ 106 1.11 christos # define TZ_MAX_TIMES 2000 107 1.8 christos #endif /* !defined TZ_MAX_TIMES */ 108 1.8 christos 109 1.8 christos #ifndef TZ_MAX_TYPES 110 1.12 christos /* This must be at least 18 for Europe/Vilnius with 'zic -b fat'. */ 111 1.11 christos # define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ 112 1.8 christos #endif /* !defined TZ_MAX_TYPES */ 113 1.1 cgd 114 1.8 christos #ifndef TZ_MAX_CHARS 115 1.12 christos /* This must be at least 40 for America/Anchorage. */ 116 1.11 christos # define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ 117 1.8 christos /* (limited by what unsigned chars can hold) */ 118 1.8 christos #endif /* !defined TZ_MAX_CHARS */ 119 1.1 cgd 120 1.8 christos #ifndef TZ_MAX_LEAPS 121 1.12 christos /* This must be at least 27 for leap seconds from 1972 through mid-2023. 122 1.12 christos There's a plan to discontinue leap seconds by 2035. */ 123 1.11 christos # define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ 124 1.8 christos #endif /* !defined TZ_MAX_LEAPS */ 125 1.1 cgd 126 1.1 cgd #define SECSPERMIN 60 127 1.1 cgd #define MINSPERHOUR 60 128 1.1 cgd #define HOURSPERDAY 24 129 1.1 cgd #define DAYSPERWEEK 7 130 1.1 cgd #define DAYSPERNYEAR 365 131 1.1 cgd #define DAYSPERLYEAR 366 132 1.1 cgd #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) 133 1.8 christos #define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY) 134 1.1 cgd #define MONSPERYEAR 12 135 1.13 christos #define YEARSPERREPEAT 400 136 1.1 cgd 137 1.1 cgd #define TM_SUNDAY 0 138 1.1 cgd #define TM_MONDAY 1 139 1.1 cgd #define TM_TUESDAY 2 140 1.1 cgd #define TM_WEDNESDAY 3 141 1.1 cgd #define TM_THURSDAY 4 142 1.1 cgd #define TM_FRIDAY 5 143 1.1 cgd #define TM_SATURDAY 6 144 1.1 cgd 145 1.1 cgd #define TM_JANUARY 0 146 1.1 cgd #define TM_FEBRUARY 1 147 1.1 cgd #define TM_MARCH 2 148 1.1 cgd #define TM_APRIL 3 149 1.1 cgd #define TM_MAY 4 150 1.1 cgd #define TM_JUNE 5 151 1.1 cgd #define TM_JULY 6 152 1.1 cgd #define TM_AUGUST 7 153 1.1 cgd #define TM_SEPTEMBER 8 154 1.1 cgd #define TM_OCTOBER 9 155 1.1 cgd #define TM_NOVEMBER 10 156 1.1 cgd #define TM_DECEMBER 11 157 1.1 cgd 158 1.1 cgd #define TM_YEAR_BASE 1900 159 1.1 cgd 160 1.1 cgd #define EPOCH_YEAR 1970 161 1.1 cgd #define EPOCH_WDAY TM_THURSDAY 162 1.1 cgd 163 1.8 christos #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) 164 1.8 christos 165 1.1 cgd /* 166 1.8 christos ** Since everything in isleap is modulo 400 (or a factor of 400), we know that 167 1.8 christos ** isleap(y) == isleap(y % 400) 168 1.8 christos ** and so 169 1.8 christos ** isleap(a + b) == isleap((a + b) % 400) 170 1.8 christos ** or 171 1.8 christos ** isleap(a + b) == isleap(a % 400 + b % 400) 172 1.8 christos ** This is true even if % means modulo rather than Fortran remainder 173 1.8 christos ** (which is allowed by C89 but not C99). 174 1.8 christos ** We use this to avoid addition overflow problems. 175 1.1 cgd */ 176 1.1 cgd 177 1.8 christos #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) 178 1.1 cgd 179 1.8 christos #endif /* !defined _TZFILE_H_ */ 180