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