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