Home | History | Annotate | Line # | Download | only in include
tzfile.h revision 1.10
      1  1.10  christos /*	$NetBSD: tzfile.h,v 1.10 2019/07/03 15:49:21 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.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.8  christos ** (with nothing between the newlines if there is no POSIX representation for
     89   1.8  christos ** 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.8  christos ** First, the POSIX 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.8  christos #define TZ_MAX_TIMES	2000
    106   1.8  christos #endif /* !defined TZ_MAX_TIMES */
    107   1.8  christos 
    108   1.8  christos #ifndef TZ_MAX_TYPES
    109   1.8  christos /* This must be at least 17 for Europe/Samara and Europe/Vilnius.  */
    110   1.8  christos #define TZ_MAX_TYPES	256 /* Limited by what (unsigned char)'s can hold */
    111   1.8  christos #endif /* !defined TZ_MAX_TYPES */
    112   1.1       cgd 
    113   1.8  christos #ifndef TZ_MAX_CHARS
    114   1.1       cgd #define TZ_MAX_CHARS	50	/* Maximum number of abbreviation characters */
    115   1.8  christos 				/* (limited by what unsigned chars can hold) */
    116   1.8  christos #endif /* !defined TZ_MAX_CHARS */
    117   1.1       cgd 
    118   1.8  christos #ifndef TZ_MAX_LEAPS
    119   1.8  christos #define TZ_MAX_LEAPS	50	/* Maximum number of leap second corrections */
    120   1.8  christos #endif /* !defined TZ_MAX_LEAPS */
    121   1.1       cgd 
    122   1.1       cgd #define SECSPERMIN	60
    123   1.1       cgd #define MINSPERHOUR	60
    124   1.1       cgd #define HOURSPERDAY	24
    125   1.1       cgd #define DAYSPERWEEK	7
    126   1.1       cgd #define DAYSPERNYEAR	365
    127   1.1       cgd #define DAYSPERLYEAR	366
    128   1.1       cgd #define SECSPERHOUR	(SECSPERMIN * MINSPERHOUR)
    129   1.8  christos #define SECSPERDAY	((int_fast32_t) SECSPERHOUR * HOURSPERDAY)
    130   1.1       cgd #define MONSPERYEAR	12
    131   1.1       cgd 
    132   1.1       cgd #define TM_SUNDAY	0
    133   1.1       cgd #define TM_MONDAY	1
    134   1.1       cgd #define TM_TUESDAY	2
    135   1.1       cgd #define TM_WEDNESDAY	3
    136   1.1       cgd #define TM_THURSDAY	4
    137   1.1       cgd #define TM_FRIDAY	5
    138   1.1       cgd #define TM_SATURDAY	6
    139   1.1       cgd 
    140   1.1       cgd #define TM_JANUARY	0
    141   1.1       cgd #define TM_FEBRUARY	1
    142   1.1       cgd #define TM_MARCH	2
    143   1.1       cgd #define TM_APRIL	3
    144   1.1       cgd #define TM_MAY		4
    145   1.1       cgd #define TM_JUNE		5
    146   1.1       cgd #define TM_JULY		6
    147   1.1       cgd #define TM_AUGUST	7
    148   1.1       cgd #define TM_SEPTEMBER	8
    149   1.1       cgd #define TM_OCTOBER	9
    150   1.1       cgd #define TM_NOVEMBER	10
    151   1.1       cgd #define TM_DECEMBER	11
    152   1.1       cgd 
    153   1.1       cgd #define TM_YEAR_BASE	1900
    154   1.1       cgd 
    155   1.1       cgd #define EPOCH_YEAR	1970
    156   1.1       cgd #define EPOCH_WDAY	TM_THURSDAY
    157   1.1       cgd 
    158   1.8  christos #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
    159   1.8  christos 
    160   1.1       cgd /*
    161   1.8  christos ** Since everything in isleap is modulo 400 (or a factor of 400), we know that
    162   1.8  christos **	isleap(y) == isleap(y % 400)
    163   1.8  christos ** and so
    164   1.8  christos **	isleap(a + b) == isleap((a + b) % 400)
    165   1.8  christos ** or
    166   1.8  christos **	isleap(a + b) == isleap(a % 400 + b % 400)
    167   1.8  christos ** This is true even if % means modulo rather than Fortran remainder
    168   1.8  christos ** (which is allowed by C89 but not C99).
    169   1.8  christos ** We use this to avoid addition overflow problems.
    170   1.1       cgd */
    171   1.1       cgd 
    172   1.8  christos #define isleap_sum(a, b)	isleap((a) % 400 + (b) % 400)
    173   1.1       cgd 
    174   1.8  christos #endif /* !defined _TZFILE_H_ */
    175