xref: /titanic_51/usr/src/lib/libast/common/tm/tmdata.c (revision 48bc00d6814e04ff3edb32cafe7d1bc580baff68)
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 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 
98 /*
99  * format[] lex type classes
100  */
101 
102 static char		lex[] =
103 {
104 	TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,
105 	TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,
106 	TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,TM_MONTH_ABBREV,
107 
108 	TM_MONTH,	TM_MONTH,	TM_MONTH,	TM_MONTH,
109 	TM_MONTH,	TM_MONTH,	TM_MONTH,	TM_MONTH,
110 	TM_MONTH,	TM_MONTH,	TM_MONTH,	TM_MONTH,
111 
112 	TM_DAY_ABBREV,	TM_DAY_ABBREV,	TM_DAY_ABBREV,	TM_DAY_ABBREV,
113 	TM_DAY_ABBREV,	TM_DAY_ABBREV,	TM_DAY_ABBREV,
114 
115 	TM_DAY,		TM_DAY,		TM_DAY,		TM_DAY,
116 	TM_DAY,		TM_DAY,		TM_DAY,
117 
118 	0,		0,		0,
119 
120 	TM_MERIDIAN,	TM_MERIDIAN,
121 
122 	TM_UT,		TM_UT,		TM_UT,		TM_UT,
123 	TM_DT,		TM_DT,		TM_DT,		TM_DT,
124 
125 	TM_SUFFIXES,	TM_SUFFIXES,	TM_SUFFIXES,	TM_SUFFIXES,
126 
127 	TM_PARTS,	TM_PARTS,	TM_PARTS,	TM_PARTS,
128 	TM_PARTS,	TM_PARTS,	TM_PARTS,
129 
130 	TM_HOURS,	TM_HOURS,	TM_HOURS,	TM_HOURS,
131 
132 	TM_DAYS,	TM_DAYS,	TM_DAYS,
133 
134 	TM_LAST,	TM_LAST,	TM_LAST,
135 	TM_THIS,	TM_THIS,	TM_THIS,
136 	TM_NEXT,	TM_NEXT,	TM_NEXT,
137 	TM_EXACT,	TM_EXACT,	TM_EXACT,
138 
139 	TM_NOISE,	TM_NOISE,	TM_NOISE,	TM_NOISE,
140 
141 	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,
142 	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,	TM_ORDINAL,
143 
144 	0,		0,		0,		0,		0,
145 	0,		0,		0,		0,		0,
146 
147 	0,		0,		0,
148 	0,		0,		0,
149 
150 	0,		0,		0,		0,		0,
151 
152 	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,
153 	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,	TM_ORDINALS,
154 
155 	TM_FINAL,	TM_FINAL,	TM_FINAL,
156 };
157 
158 /*
159  * output format digits
160  */
161 
162 static char	digit[] = "0123456789";
163 
164 /*
165  * number of days in month i
166  */
167 
168 static short	days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
169 
170 /*
171  * sum of days in months before month i
172  */
173 
174 static short	sum[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
175 
176 /*
177  * leap second time_t and accumulated adjustments
178  * (reverse order -- biased for recent dates)
179  *
180  * tl.time is the seconds since the epoch for the leap event
181  *
182  *	adding:		the first additional second
183  *	subtracting:	the first dissappearing second
184  */
185 
186 static Tm_leap_t	leap[] =
187 {
188 	 1136073622,   23,		/* 2005-12-31+23:59:60 UTC*/
189 	  915148821,   22,		/* 1998-12-31+23:59:60 UTC */
190 	  867715220,   21,		/* 1997-06-30+23:59:60 UTC */
191 	  820454419,   20,		/* 1995-12-31+23:59:60 UTC */
192 	  773020818,   19,		/* 1994-06-30+23:59:60 UTC */
193 	  741484817,   18,		/* 1993-06-30+23:59:60 UTC */
194 	  709948816,   17,		/* 1992-06-30+23:59:60 UTC */
195 	  662688015,   16,		/* 1990-12-31+23:59:60 UTC */
196 	  631152014,   15,		/* 1989-12-31+23:59:60 UTC */
197 	  567993613,   14,		/* 1987-12-31+23:59:60 UTC */
198 	  489024012,   13,		/* 1985-06-30+23:59:60 UTC */
199 	  425865611,   12,		/* 1983-06-30+23:59:60 UTC */
200 	  394329610,   11,		/* 1982-06-30+23:59:60 UTC */
201 	  362793609,   10,		/* 1981-06-30+23:59:60 UTC */
202 	  315532808,    9,		/* 1979-12-31+23:59:60 UTC */
203 	  283996807,    8,		/* 1978-12-31+23:59:60 UTC */
204 	  252460806,    7,		/* 1977-12-31+23:59:60 UTC */
205 	  220924805,    6,		/* 1976-12-31+23:59:60 UTC */
206 	  189302404,    5,		/* 1975-12-31+23:59:60 UTC */
207 	  157766403,    4,		/* 1974-12-31+23:59:60 UTC */
208 	  126230402,    3,		/* 1973-12-31+23:59:60 UTC */
209 	   94694401,    2,		/* 1972-12-31+23:59:60 UTC */
210 	   78796800,    1,		/* 1972-06-30+23:59:60 UTC */
211 		  0,    0,		/* can reference (tl+1)     */
212 		  0,    0
213 };
214 
215 /*
216  * time zones
217  *
218  * the UTC entries must be first
219  *
220  * zones with the same type are contiguous with all but the
221  * first entry for the type having a null type
222  *
223  * tz.standard is the sentinel
224  */
225 
226 static Tm_zone_t	zone[] =
227 {
228  0,	"GMT",	0,	 ( 0 * 60),	     0,	/* UTC			*/
229  0,	"UCT",	0,	 ( 0 * 60),	     0,	/* UTC			*/
230  0,	"UTC",	0,	 ( 0 * 60),	     0,	/* UTC			*/
231  0,	"CUT",	0,	 ( 0 * 60),	     0,	/* UTC			*/
232  0,	"Z",	0,	 ( 0 * 60),	     0,	/* UTC			*/
233  "USA",	"HST",	0,	 (10 * 60),	     0,	/* Hawaii		*/
234  0,	"YST",	"YDT",	 ( 9 * 60),	TM_DST,	/* Yukon		*/
235  0,	"PST",	"PDT",	 ( 8 * 60),	TM_DST,	/* Pacific		*/
236  0,	"PST",	"PPET",	 ( 8 * 60),	TM_DST,	/* Pacific pres elect	*/
237  0,	"MST",	"MDT",	 ( 7 * 60),	TM_DST,	/* Mountain		*/
238  0,	"CST",	"CDT",	 ( 6 * 60),	TM_DST,	/* Central		*/
239  0,	"EST",	"EDT",	 ( 5 * 60),	TM_DST,	/* Eastern		*/
240  "CAN",	"AST",	"ADT",	 ( 4 * 60),	TM_DST,	/* Atlantic		*/
241  0,	"NST",	0,	 ( 3 * 60 + 30),     0,	/* Newfoundland		*/
242  "GBR",	"",	"BST",	 ( 0 * 60),	TM_DST,	/* British Summer	*/
243  "EUR",	"WET",	0,	 ( 0 * 60),	TM_DST,	/* Western Eurpoean	*/
244  0,	"CET",	0,	-( 1 * 60),	TM_DST,	/* Central European	*/
245  0,	"MET",	0,	-( 1 * 60),	TM_DST,	/* Middle European	*/
246  0,	"EET",	0,	-( 2 * 60),	TM_DST,	/* Eastern Eurpoean	*/
247  "ISR",	"IST",	"IDT",  -( 3 * 60),	TM_DST,	/* Israel		*/
248  "IND",	"IST",	0,  	-( 5 * 60 + 30 ),    0,	/* India		*/
249  "CHN",	"HKT",	0,	-( 8 * 60),	     0,	/* Hong Kong		*/
250  "KOR",	"KST",	"KDT",	-( 8 * 60),	TM_DST,	/* Korea		*/
251  "SNG",	"SST",	0,	-( 8 * 60),	     0,	/* Singapore		*/
252  "JPN",	"JST",	0,	-( 9 * 60),	     0,	/* Japan		*/
253  "AUS",	"AWST",	0,	-( 8 * 60),	     0,	/* Australia Western	*/
254  0,	"WST",	0,	-( 8 * 60),	     0,	/* Australia Western	*/
255  0,	"ACST",	0,	-( 9 * 60 + 30),TM_DST,	/* Australia Central	*/
256  0,	"CST",	0,	-( 9 * 60 + 30),TM_DST,	/* Australia Central	*/
257  0,	"AEST",	0,	-(10 * 60),	TM_DST,	/* Australia Eastern	*/
258  0,	"EST",	0,	-(10 * 60),	TM_DST,	/* Australia Eastern	*/
259  "NZL",	"NZST",	"NZDT",	-(12 * 60),	TM_DST,	/* New Zealand		*/
260  0,	0,	0,	0,		     0
261 };
262 
263 /*
264  * 2007-03-19 move tm_data from _tm_data_ to (*_tm_datap_)
265  *	      to allow future Tm_data_t growth
266  *            by 2009 _tm_data_ can be static
267  */
268 
269 #if _BLD_ast && defined(__EXPORT__)
270 #define extern		extern __EXPORT__
271 #endif
272 
273 extern Tm_data_t	_tm_data_;
274 
275 #undef	extern
276 
277 Tm_data_t _tm_data_ = { format, lex, digit, days, sum, leap, zone };
278 
279 __EXTERN__(Tm_data_t, _tm_data_);
280 
281 __EXTERN__(Tm_data_t*, _tm_datap_);
282 
283 Tm_data_t*		_tm_datap_ = &_tm_data_;
284