xref: /titanic_51/usr/src/lib/libast/common/include/tm.h (revision a31148363f598def767ac48c5d82e1572e44b935)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2009 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * AT&T Research
26  *
27  * time conversion support definitions
28  */
29 
30 #ifndef _TM_H
31 #define _TM_H
32 
33 #define TM_VERSION	20070319L
34 
35 #include <ast.h>
36 #include <times.h>
37 
38 #undef	daylight
39 
40 #define tmset(z)	tminit(z)
41 #define tmisleapyear(y)	(!((y)%4)&&(((y)%100)||!((((y)<1900)?((y)+1900):(y))%400)))
42 
43 #define TM_ADJUST	(1<<0)		/* local doesn't do leap secs	*/
44 #define TM_LEAP		(1<<1)		/* do leap seconds		*/
45 #define TM_UTC		(1<<2)		/* universal coordinated ref	*/
46 
47 #define TM_PEDANTIC	(1<<3)		/* pedantic date parse		*/
48 #define TM_DATESTYLE	(1<<4)		/* date(1) style mmddHHMMccyy	*/
49 #define TM_SUBSECOND	(1<<5)		/* <something>%S => ...%S.%P	*/
50 
51 #define TM_DST		(-60)		/* default minutes for DST	*/
52 #define TM_LOCALZONE	(25 * 60)	/* use local time zone offset	*/
53 #define TM_UTCZONE	(26 * 60)	/* UTC "time zone"		*/
54 #define TM_MAXLEAP	1		/* max leap secs per leap	*/
55 #define TM_WINDOW	69		/* century windowing guard year	*/
56 
57 /*
58  * these indices must agree with tm_dform[]
59  */
60 
61 #define TM_MONTH_ABBREV		0
62 #define TM_MONTH		12
63 #define TM_DAY_ABBREV		24
64 #define TM_DAY			31
65 #define TM_TIME			38
66 #define TM_DATE			39
67 #define TM_DEFAULT		40
68 #define TM_MERIDIAN		41
69 
70 #define TM_UT			43
71 #define TM_DT			47
72 #define TM_SUFFIXES		51
73 #define TM_PARTS		55
74 #define TM_HOURS		62
75 #define TM_DAYS			66
76 #define TM_LAST			69
77 #define TM_THIS			72
78 #define TM_NEXT			75
79 #define TM_EXACT		78
80 #define TM_NOISE		81
81 #define TM_ORDINAL		85
82 #define TM_DIGITS		95
83 #define TM_CTIME		105
84 #define TM_DATE_1		106
85 #define TM_INTERNATIONAL	107
86 #define TM_RECENT		108
87 #define TM_DISTANT		109
88 #define TM_MERIDIAN_TIME	110
89 #define TM_ERA			111
90 #define TM_ERA_DATE		112
91 #define TM_ERA_TIME		113
92 #define TM_ERA_DEFAULT		114
93 #define TM_ERA_YEAR		115
94 #define TM_ORDINALS		116
95 #define TM_FINAL		126
96 #define TM_WORK			129
97 
98 #define TM_NFORM		132
99 
100 typedef struct				/* leap second info		*/
101 {
102 	time_t		time;		/* the leap second event	*/
103 	int		total;		/* inclusive total since epoch	*/
104 } Tm_leap_t;
105 
106 typedef struct				/* time zone info		*/
107 {
108 	char*		type;		/* type name			*/
109 	char*		standard;	/* standard time name		*/
110 	char*		daylight;	/* daylight or summertime name	*/
111 	short		west;		/* minutes west of GMT		*/
112 	short		dst;		/* add to tz.west for DST	*/
113 } Tm_zone_t;
114 
115 typedef struct				/* tm library readonly data	*/
116 {
117 	char**		format;		/* default TM_* format strings	*/
118 	unsigned char*	lex;		/* format lex type classes	*/
119 	char*		digit;		/* output digits		*/
120 	short*		days;		/* days in month i		*/
121 	short*		sum;		/* days in months before i	*/
122 	Tm_leap_t*	leap;		/* leap second table		*/
123 	Tm_zone_t*	zone;		/* alternate timezone table	*/
124 } Tm_data_t;
125 
126 typedef struct				/* tm library global info	*/
127 {
128 	char*		deformat;	/* TM_DEFAULT override		*/
129 	int		flags;		/* flags			*/
130 	char**		format;		/* current format strings	*/
131 	Tm_zone_t*	date;		/* timezone from last tmdate()	*/
132 	Tm_zone_t*	local;		/* local timezone		*/
133 	Tm_zone_t*	zone;		/* current timezone		*/
134 } Tm_info_t;
135 
136 typedef struct Tm_s
137 {
138 	int			tm_sec;
139 	int			tm_min;
140 	int			tm_hour;
141 	int			tm_mday;
142 	int			tm_mon;
143 	int			tm_year;
144 	int			tm_wday;
145 	int			tm_yday;
146 	int			tm_isdst;
147 	uint32_t		tm_nsec;
148 	Tm_zone_t*		tm_zone;
149 } Tm_t;
150 
151 #if _BLD_ast && defined(__EXPORT__)
152 #define extern		extern __EXPORT__
153 #endif
154 #if !_BLD_ast && defined(__IMPORT__)
155 #define extern		extern __IMPORT__
156 #endif
157 
158 extern Tm_data_t*	_tm_datap_;
159 extern Tm_info_t*	_tm_infop_;
160 
161 #define tm_data		(*_tm_datap_)
162 #define tm_info		(*_tm_infop_)
163 
164 #undef	extern
165 
166 #if _BLD_ast && defined(__EXPORT__)
167 #define extern		__EXPORT__
168 #endif
169 
170 extern time_t		tmdate(const char*, char**, time_t*);
171 extern int		tmequiv(Tm_t*);
172 extern Tm_t*		tmfix(Tm_t*);
173 extern char*		tmfmt(char*, size_t, const char*, time_t*);
174 extern char*		tmform(char*, const char*, time_t*);
175 extern int		tmgoff(const char*, char**, int);
176 extern void		tminit(Tm_zone_t*);
177 extern time_t		tmleap(time_t*);
178 extern int		tmlex(const char*, char**, char**, int, char**, int);
179 extern char**		tmlocale(void);
180 extern Tm_t*		tmmake(time_t*);
181 extern char*		tmpoff(char*, size_t, const char*, int, int);
182 extern time_t		tmscan(const char*, char**, const char*, char**, time_t*, long);
183 extern int		tmsleep(time_t, time_t);
184 extern time_t		tmtime(Tm_t*, int);
185 extern Tm_zone_t*	tmtype(const char*, char**);
186 extern int		tmweek(Tm_t*, int, int, int);
187 extern int		tmword(const char*, char**, const char*, char**, int);
188 extern Tm_zone_t*	tmzone(const char*, char**, const char*, int*);
189 
190 #undef	extern
191 
192 #endif
193