187043Sache#ifndef TZFILE_H
287043Sache#define TZFILE_H
387043Sache
487043Sache
587043Sache/*
687043Sache** This file is in the public domain, so clarified as of
787043Sache** 1996-06-05 by Arthur David Olson.
887043Sache**
987043Sache** $FreeBSD$
1087043Sache*/
1187043Sache
1287043Sache/*
1387043Sache** This header is for use ONLY with the time conversion code.
1487043Sache** There is no guarantee that it will remain unchanged,
1587043Sache** or that it will remain at all.
1687043Sache** Do NOT copy it to any system include directory.
1787043Sache** Thank you!
1887043Sache*/
1987043Sache
2087043Sache/*
2187043Sache** ID
2287043Sache*/
2387043Sache
2487043Sache#ifndef lint
2587043Sache#ifndef NOID
2687043Sache/*
2787043Sachestatic char	tzfilehid[] = "@(#)tzfile.h	8.1";
2887043Sache*/
2987043Sache#endif /* !defined NOID */
3087043Sache#endif /* !defined lint */
3187043Sache
3287043Sache/*
3387043Sache** Information about time zone files.
3487043Sache*/
3587043Sache
3687043Sache#ifndef TZDIR
3787043Sache#define TZDIR	"/usr/share/zoneinfo" /* Time zone object file directory */
3887043Sache#endif /* !defined TZDIR */
3987043Sache
4087043Sache#ifndef TZDEFAULT
4187043Sache#define TZDEFAULT	"/etc/localtime"
4287043Sache#endif /* !defined TZDEFAULT */
4387043Sache
4487043Sache#ifndef TZDEFRULES
4587043Sache#define TZDEFRULES	"posixrules"
4687043Sache#endif /* !defined TZDEFRULES */
4787043Sache
4887043Sache/*
4987043Sache** Each file begins with. . .
5087043Sache*/
5187043Sache
5287043Sache#define	TZ_MAGIC	"TZif"
5387043Sache
5487043Sachestruct tzhead {
5587043Sache	char	tzh_magic[4];		/* TZ_MAGIC */
5687043Sache	char	tzh_version[1];		/* '\0' or '2' as of 2005 */
5787043Sache	char	tzh_reserved[15];	/* reserved--must be zero */
5887043Sache	char	tzh_ttisgmtcnt[4];	/* coded number of trans. time flags */
5987043Sache	char	tzh_ttisstdcnt[4];	/* coded number of trans. time flags */
6087043Sache	char	tzh_leapcnt[4];		/* coded number of leap seconds */
6187043Sache	char	tzh_timecnt[4];		/* coded number of transition times */
6287043Sache	char	tzh_typecnt[4];		/* coded number of local time types */
6387043Sache	char	tzh_charcnt[4];		/* coded number of abbr. chars */
6487043Sache};
6587043Sache
6687043Sache/*
6787043Sache** . . .followed by. . .
6887043Sache**
6987043Sache**	tzh_timecnt (char [4])s		coded transition times a la time(2)
7087043Sache**	tzh_timecnt (unsigned char)s	types of local time starting at above
7187043Sache**	tzh_typecnt repetitions of
7287043Sache**		one (char [4])		coded UTC offset in seconds
7387043Sache**		one (unsigned char)	used to set tm_isdst
7487043Sache**		one (unsigned char)	that's an abbreviation list index
7587043Sache**	tzh_charcnt (char)s		'\0'-terminated zone abbreviations
7687043Sache**	tzh_leapcnt repetitions of
7787043Sache**		one (char [4])		coded leap second transition times
7887043Sache**		one (char [4])		total correction after above
7987043Sache**	tzh_ttisstdcnt (char)s		indexed by type; if TRUE, transition
8087043Sache**					time is standard time, if FALSE,
8187043Sache**					transition time is wall clock time
8287043Sache**					if absent, transition times are
8387043Sache**					assumed to be wall clock time
8487043Sache**	tzh_ttisgmtcnt (char)s		indexed by type; if TRUE, transition
8587043Sache**					time is UTC, if FALSE,
8687043Sache**					transition time is local time
8787043Sache**					if absent, transition times are
8887043Sache**					assumed to be local time
8987043Sache*/
9087043Sache
9187043Sache/*
9287043Sache** If tzh_version is '2' or greater, the above is followed by a second instance
9387043Sache** of tzhead and a second instance of the data in which each coded transition
9487043Sache** time uses 8 rather than 4 chars,
9587043Sache** then a POSIX-TZ-environment-variable-style string for use in handling
9687043Sache** instants after the last transition time stored in the file
9787043Sache** (with nothing between the newlines if there is no POSIX representation for
9887043Sache** such instants).
9987043Sache*/
10087043Sache
10187043Sache/*
10287043Sache** In the current implementation, "tzset()" refuses to deal with files that
10387043Sache** exceed any of the limits below.
10487043Sache*/
10587043Sache
10687043Sache#ifndef TZ_MAX_TIMES
10787043Sache#define TZ_MAX_TIMES	1200
10887043Sache#endif /* !defined TZ_MAX_TIMES */
10987043Sache
11087043Sache#ifndef TZ_MAX_TYPES
11187043Sache#ifndef NOSOLAR
11287043Sache#define TZ_MAX_TYPES	256 /* Limited by what (unsigned char)'s can hold */
11387043Sache#endif /* !defined NOSOLAR */
11487043Sache#ifdef NOSOLAR
11587043Sache/*
11687043Sache** Must be at least 14 for Europe/Riga as of Jan 12 1995,
11787043Sache** as noted by Earl Chew.
11887043Sache*/
11987043Sache#define TZ_MAX_TYPES	20	/* Maximum number of local time types */
12087043Sache#endif /* !defined NOSOLAR */
12187043Sache#endif /* !defined TZ_MAX_TYPES */
12287043Sache
12387043Sache#ifndef TZ_MAX_CHARS
12487043Sache#define TZ_MAX_CHARS	50	/* Maximum number of abbreviation characters */
12587043Sache				/* (limited by what unsigned chars can hold) */
12687043Sache#endif /* !defined TZ_MAX_CHARS */
12787043Sache
12887043Sache#ifndef TZ_MAX_LEAPS
12987043Sache#define TZ_MAX_LEAPS	50	/* Maximum number of leap second corrections */
13087043Sache#endif /* !defined TZ_MAX_LEAPS */
13187043Sache
13287043Sache#define SECSPERMIN	60
13387043Sache#define MINSPERHOUR	60
13487043Sache#define HOURSPERDAY	24
13587043Sache#define DAYSPERWEEK	7
13687043Sache#define DAYSPERNYEAR	365
13787043Sache#define DAYSPERLYEAR	366
13887043Sache#define SECSPERHOUR	(SECSPERMIN * MINSPERHOUR)
13987043Sache#define SECSPERDAY	((long) SECSPERHOUR * HOURSPERDAY)
14087043Sache#define MONSPERYEAR	12
14187043Sache
14287043Sache#define TM_SUNDAY	0
14387043Sache#define TM_MONDAY	1
14487043Sache#define TM_TUESDAY	2
14587043Sache#define TM_WEDNESDAY	3
14687043Sache#define TM_THURSDAY	4
14787043Sache#define TM_FRIDAY	5
14887043Sache#define TM_SATURDAY	6
14987043Sache
15087043Sache#define TM_JANUARY	0
15187043Sache#define TM_FEBRUARY	1
15287043Sache#define TM_MARCH	2
15387043Sache#define TM_APRIL	3
15487043Sache#define TM_MAY		4
15587043Sache#define TM_JUNE		5
15687043Sache#define TM_JULY		6
15787043Sache#define TM_AUGUST	7
15887043Sache#define TM_SEPTEMBER	8
15987043Sache#define TM_OCTOBER	9
16087043Sache#define TM_NOVEMBER	10
16187043Sache#define TM_DECEMBER	11
16287043Sache
16387043Sache#define TM_YEAR_BASE	1900
16487043Sache
165#define EPOCH_YEAR	1970
166#define EPOCH_WDAY	TM_THURSDAY
167
168#define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
169
170/*
171** Since everything in isleap is modulo 400 (or a factor of 400), we know that
172**	isleap(y) == isleap(y % 400)
173** and so
174**	isleap(a + b) == isleap((a + b) % 400)
175** or
176**	isleap(a + b) == isleap(a % 400 + b % 400)
177** This is true even if % means modulo rather than Fortran remainder
178** (which is allowed by C89 but not C99).
179** We use this to avoid addition overflow problems.
180*/
181
182#define isleap_sum(a, b)	isleap((a) % 400 + (b) % 400)
183
184#endif /* !defined TZFILE_H */
185