xref: /titanic_44/usr/src/lib/libast/common/include/tm.h (revision 2d6b5ea734bb47d251c82670646fde46af15fd69)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2008 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 
97 #define TM_NFORM		129
98 
99 typedef struct				/* leap second info		*/
100 {
101 	time_t		time;		/* the leap second event	*/
102 	int		total;		/* inclusive total since epoch	*/
103 } Tm_leap_t;
104 
105 typedef struct				/* time zone info		*/
106 {
107 	char*		type;		/* type name			*/
108 	char*		standard;	/* standard time name		*/
109 	char*		daylight;	/* daylight or summertime name	*/
110 	short		west;		/* minutes west of GMT		*/
111 	short		dst;		/* add to tz.west for DST	*/
112 } Tm_zone_t;
113 
114 typedef struct				/* tm library readonly data	*/
115 {
116 	char**		format;		/* default TM_* format strings	*/
117 	char*		lex;		/* format lex type classes	*/
118 	char*		digit;		/* output digits		*/
119 	short*		days;		/* days in month i		*/
120 	short*		sum;		/* days in months before i	*/
121 	Tm_leap_t*	leap;		/* leap second table		*/
122 	Tm_zone_t*	zone;		/* alternate timezone table	*/
123 } Tm_data_t;
124 
125 typedef struct				/* tm library global info	*/
126 {
127 	char*		deformat;	/* TM_DEFAULT override		*/
128 	int		flags;		/* flags			*/
129 	char**		format;		/* current format strings	*/
130 	Tm_zone_t*	date;		/* timezone from last tmdate()	*/
131 	Tm_zone_t*	local;		/* local timezone		*/
132 	Tm_zone_t*	zone;		/* current timezone		*/
133 } Tm_info_t;
134 
135 typedef struct Tm_s
136 {
137 	int			tm_sec;
138 	int			tm_min;
139 	int			tm_hour;
140 	int			tm_mday;
141 	int			tm_mon;
142 	int			tm_year;
143 	int			tm_wday;
144 	int			tm_yday;
145 	int			tm_isdst;
146 	uint32_t		tm_nsec;
147 	Tm_zone_t*		tm_zone;
148 } Tm_t;
149 
150 #if _BLD_ast && defined(__EXPORT__)
151 #define extern		extern __EXPORT__
152 #endif
153 #if !_BLD_ast && defined(__IMPORT__)
154 #define extern		extern __IMPORT__
155 #endif
156 
157 extern Tm_data_t*	_tm_datap_;
158 extern Tm_info_t*	_tm_infop_;
159 
160 #define tm_data		(*_tm_datap_)
161 #define tm_info		(*_tm_infop_)
162 
163 #undef	extern
164 
165 #if _BLD_ast && defined(__EXPORT__)
166 #define extern		__EXPORT__
167 #endif
168 
169 extern time_t		tmdate(const char*, char**, time_t*);
170 extern int		tmequiv(Tm_t*);
171 extern Tm_t*		tmfix(Tm_t*);
172 extern char*		tmfmt(char*, size_t, const char*, time_t*);
173 extern char*		tmform(char*, const char*, time_t*);
174 extern int		tmgoff(const char*, char**, int);
175 extern void		tminit(Tm_zone_t*);
176 extern time_t		tmleap(time_t*);
177 extern int		tmlex(const char*, char**, char**, int, char**, int);
178 extern char**		tmlocale(void);
179 extern Tm_t*		tmmake(time_t*);
180 extern char*		tmpoff(char*, size_t, const char*, int, int);
181 extern time_t		tmscan(const char*, char**, const char*, char**, time_t*, long);
182 extern int		tmsleep(time_t, time_t);
183 extern time_t		tmtime(Tm_t*, int);
184 extern Tm_zone_t*	tmtype(const char*, char**);
185 extern int		tmweek(Tm_t*, int, int, int);
186 extern int		tmword(const char*, char**, const char*, char**, int);
187 extern Tm_zone_t*	tmzone(const char*, char**, const char*, int*);
188 
189 #undef	extern
190 
191 #endif
192