xref: /titanic_51/usr/src/lib/libast/common/tm/tmdata.c (revision 34de876298c5177ddeb98f3af7e4e3012f16e2a7)
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 readonly data
28  */
29 
30 #include <ast.h>
31 #include <tm.h>
32 
33 /*
34  * default format strings -- must agree with TM_* indices
35  */
36 
37 static char*		format[] =
38 {
39 	"Jan",		"Feb",		"Mar",		"Apr",
40 	"May",		"Jun",		"Jul",		"Aug",
41 	"Sep",		"Oct",		"Nov",		"Dec",
42 
43 	"January",	"February",	"March",	"April",
44 	"May",		"June",		"July",		"August",
45 	"September",	"October",	"November",	"December",
46 
47 	"Sun",		"Mon",		"Tue",		"Wed",
48 	"Thu",		"Fri",		"Sat",
49 
50 	"Sunday",	"Monday",	"Tuesday",	"Wednesday",
51 	"Thursday",	"Friday",	"Saturday",
52 
53 	"%H:%M:%S",	"%m/%d/%y",	"%a %b %e %T %Z %Y",
54 
55 	"AM",		"PM",
56 
57 	"GMT",		"UTC",		"UCT",		"CUT",
58 
59 	"DST",		"",		"",		"",
60 
61 	"s",		"es",		"",		"",
62 
63 	"second",	"minute",	"hour",		"day",
64 	"week",		"month",	"year",
65 
66 	"midnight",	"morning",	"noon",		"evening",
67 
68 	"yesterday",	"today",	"tomorrow",
69 
70 	"last",		"ago",		"past",
71 	"this",		"now",		"current",
72 	"in",		"next",		"hence",
73 	"exactly",	"",		"",
74 
75 	"at",		"on",		"",		"",
76 
77 	"st",		"nd",		"rd",		"th",		"th",
78 	"th",		"th",		"th",		"th",		"th",
79 
80 	"",		"",		"",		"",		"",
81 	"",		"",		"",		"",		"",
82 
83 	"%a %b %e %T %Y",
84 	"%a %b %e %T %Z %Y",
85 	"%a %b %e %T %z %Z %Y",
86 	"%b %e %H:%M",
87 	"%b %e  %Y",
88 	"%I:%M:%S %p",
89 
90 	"",		"",		"",		"",		"",
91 
92 	"first",	"",		"third",	"fourth",	"fifth",
93 	"sixth",	"seventh",	"eighth",	"ninth",	"tenth",
94 
95 	"final",	"ending",	"nth",
96 
97 	"work",		"working",	"workday",
98 };
99 
100 /*
101  * format[] lex type classes
102  */
103 
104 static unsigned char	lex[] =
105 {
106 	TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,
107 	TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,
108 	TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,
109 
110 	TM_MONTH,	TM_MONTH,	TM_MONTH,	TM_MONTH,
111 	TM_MONTH,	TM_MONTH,	TM_MONTH,	TM_MONTH,
112 	TM_MONTH,	TM_MONTH,	TM_MONTH,	TM_MONTH,
113 
114 	TM_DAY_ABBREV,	TM_DAY_ABBREV,	TM_DAY_ABBREV,	TM_DAY_ABBREV,
115 	TM_DAY_ABBREV,	TM_DAY_ABBREV,	TM_DAY_ABBREV,
116 
117 	TM_DAY,		TM_DAY,		TM_DAY,		TM_DAY,
118 	TM_DAY,		TM_DAY,		TM_DAY,
119 
120 	0,		0,		0,
121 
122 	TM_MERIDIAN,	TM_MERIDIAN,
123 
124 	TM_UT,		TM_UT,		TM_UT,		TM_UT,
125 	TM_DT,		TM_DT,		TM_DT,		TM_DT,
126 
127 	TM_SUFFIXES,	TM_SUFFIXES,	TM_SUFFIXES,	TM_SUFFIXES,
128 
129 	TM_PARTS,	TM_PARTS,	TM_PARTS,	TM_PARTS,
130 	TM_PARTS,	TM_PARTS,	TM_PARTS,
131 
132 	TM_HOURS,	TM_HOURS,	TM_HOURS,	TM_HOURS,
133 
134 	TM_DAYS,	TM_DAYS,	TM_DAYS,
135 
136 	TM_LAST,	TM_LAST,	TM_LAST,
137 	TM_THIS,	TM_THIS,	TM_THIS,
138 	TM_NEXT,	TM_NEXT,	TM_NEXT,
139 	TM_EXACT,	TM_EXACT,	TM_EXACT,
140 
141 	TM_NOISE,	TM_NOISE,	TM_NOISE,	TM_NOISE,
142 
143 	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,
144 	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,
145 
146 	0,		0,		0,		0,		0,
147 	0,		0,		0,		0,		0,
148 
149 	0,		0,		0,
150 	0,		0,		0,
151 
152 	0,		0,		0,		0,		0,
153 
154 	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,
155 	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,
156 
157 	TM_FINAL,	TM_FINAL,	TM_FINAL,
158 
159 	TM_WORK,	TM_WORK,	TM_WORK,
160 };
161 
162 /*
163  * output format digits
164  */
165 
166 static char	digit[] = "0123456789";
167 
168 /*
169  * number of days in month i
170  */
171 
172 static short	days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
173 
174 /*
175  * sum of days in months before month i
176  */
177 
178 static short	sum[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
179 
180 /*
181  * leap second time_t and accumulated adjustments
182  * (reverse order -- biased for recent dates)
183  *
184  * tl.time is the seconds since the epoch for the leap event
185  *
186  *	adding:		the first additional second
187  *	subtracting:	the first dissappearing second
188  */
189 
190 static Tm_leap_t	leap[] =
191 {
192 	 1230768023,   24,		/* 2008-12-31+23:59:60-0000 */
193 	 1136073622,   23,		/* 2005-12-31+23:59:60-0000 */
194 	  915148821,   22,		/* 1998-12-31+23:59:60-0000 */
195 	  867715220,   21,		/* 1997-06-30+23:59:60-0000 */
196 	  820454419,   20,		/* 1995-12-31+23:59:60-0000 */
197 	  773020818,   19,		/* 1994-06-30+23:59:60-0000 */
198 	  741484817,   18,		/* 1993-06-30+23:59:60-0000 */
199 	  709948816,   17,		/* 1992-06-30+23:59:60-0000 */
200 	  662688015,   16,		/* 1990-12-31+23:59:60-0000 */
201 	  631152014,   15,		/* 1989-12-31+23:59:60-0000 */
202 	  567993613,   14,		/* 1987-12-31+23:59:60-0000 */
203 	  489024012,   13,		/* 1985-06-30+23:59:60-0000 */
204 	  425865611,   12,		/* 1983-06-30+23:59:60-0000 */
205 	  394329610,   11,		/* 1982-06-30+23:59:60-0000 */
206 	  362793609,   10,		/* 1981-06-30+23:59:60-0000 */
207 	  315532808,    9,		/* 1979-12-31+23:59:60-0000 */
208 	  283996807,    8,		/* 1978-12-31+23:59:60-0000 */
209 	  252460806,    7,		/* 1977-12-31+23:59:60-0000 */
210 	  220924805,    6,		/* 1976-12-31+23:59:60-0000 */
211 	  189302404,    5,		/* 1975-12-31+23:59:60-0000 */
212 	  157766403,    4,		/* 1974-12-31+23:59:60-0000 */
213 	  126230402,    3,		/* 1973-12-31+23:59:60-0000 */
214 	   94694401,    2,		/* 1972-12-31+23:59:60-0000 */
215 	   78796800,    1,		/* 1972-06-30+23:59:60-0000 */
216 		  0,    0,		/* can reference (tl+1)     */
217 		  0,    0
218 };
219 
220 /*
221  * time zones
222  *
223  * the UTC entries must be first
224  *
225  * zones with the same type are contiguous with all but the
226  * first entry for the type having a null type
227  *
228  * tz.standard is the sentinel
229  */
230 
231 static Tm_zone_t	zone[] =
232 {
233  0,	"GMT",	0,	 ( 0 * 60),	     0,	/* UTC			*/
234  0,	"UCT",	0,	 ( 0 * 60),	     0,	/* UTC			*/
235  0,	"UTC",	0,	 ( 0 * 60),	     0,	/* UTC			*/
236  0,	"CUT",	0,	 ( 0 * 60),	     0,	/* UTC			*/
237  0,	"Z",	0,	 ( 0 * 60),	     0,	/* UTC			*/
238  "USA",	"HST",	0,	 (10 * 60),	     0,	/* Hawaii		*/
239  0,	"YST",	"YDT",	 ( 9 * 60),	TM_DST,	/* Yukon		*/
240  0,	"PST",	"PDT",	 ( 8 * 60),	TM_DST,	/* Pacific		*/
241  0,	"PST",	"PPET",	 ( 8 * 60),	TM_DST,	/* Pacific pres elect	*/
242  0,	"MST",	"MDT",	 ( 7 * 60),	TM_DST,	/* Mountain		*/
243  0,	"CST",	"CDT",	 ( 6 * 60),	TM_DST,	/* Central		*/
244  0,	"EST",	"EDT",	 ( 5 * 60),	TM_DST,	/* Eastern		*/
245  "CAN",	"AST",	"ADT",	 ( 4 * 60),	TM_DST,	/* Atlantic		*/
246  0,	"NST",	0,	 ( 3 * 60 + 30),     0,	/* Newfoundland		*/
247  "GBR",	"",	"BST",	 ( 0 * 60),	TM_DST,	/* British Summer	*/
248  "EUR",	"WET",	"WEST",	 ( 0 * 60),	TM_DST,	/* Western Eurpoean	*/
249  0,	"CET",	"CEST",	-( 1 * 60),	TM_DST,	/* Central European	*/
250  0,	"MET",	"MEST",	-( 1 * 60),	TM_DST,	/* Middle European	*/
251  0,	"EET",	"EEST",	-( 2 * 60),	TM_DST,	/* Eastern Eurpoean	*/
252  "ISR",	"IST",	"IDT",  -( 3 * 60),	TM_DST,	/* Israel		*/
253  "IND",	"IST",	0,  	-( 5 * 60 + 30 ),    0,	/* India		*/
254  "CHN",	"HKT",	0,	-( 8 * 60),	     0,	/* Hong Kong		*/
255  "KOR",	"KST",	"KDT",	-( 8 * 60),	TM_DST,	/* Korea		*/
256  "SNG",	"SST",	0,	-( 8 * 60),	     0,	/* Singapore		*/
257  "JPN",	"JST",	0,	-( 9 * 60),	     0,	/* Japan		*/
258  "AUS",	"AWST",	0,	-( 8 * 60),	     0,	/* Australia Western	*/
259  0,	"WST",	0,	-( 8 * 60),	     0,	/* Australia Western	*/
260  0,	"ACST",	0,	-( 9 * 60 + 30),TM_DST,	/* Australia Central	*/
261  0,	"CST",	0,	-( 9 * 60 + 30),TM_DST,	/* Australia Central	*/
262  0,	"AEST",	0,	-(10 * 60),	TM_DST,	/* Australia Eastern	*/
263  0,	"EST",	0,	-(10 * 60),	TM_DST,	/* Australia Eastern	*/
264  "NZL",	"NZST",	"NZDT",	-(12 * 60),	TM_DST,	/* New Zealand		*/
265  0,	0,	0,	0,		     0
266 };
267 
268 /*
269  * 2007-03-19 move tm_data from _tm_data_ to (*_tm_datap_)
270  *	      to allow future Tm_data_t growth
271  *            by 2009 _tm_data_ can be static
272  */
273 
274 #if _BLD_ast && defined(__EXPORT__)
275 #define extern		extern __EXPORT__
276 #endif
277 
278 extern Tm_data_t	_tm_data_;
279 
280 #undef	extern
281 
282 Tm_data_t _tm_data_ = { format, lex, digit, days, sum, leap, zone };
283 
284 __EXTERN__(Tm_data_t, _tm_data_);
285 
286 __EXTERN__(Tm_data_t*, _tm_datap_);
287 
288 Tm_data_t*		_tm_datap_ = &_tm_data_;
289