14 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
29 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
38 #if !defined(HAVE_TM_GMTOFF) && !defined(HAVE_TZSET)
39 # include <sys/timeb.h>
42 #if !defined(HAVE_TM_GMTOFF) && defined(HAVE_TZSET)
45 extern char *tzname[];
49 * Patchable flag that says how to interpret NN/NN/NN dates. When
50 * true, we do it European style: DD/MM/YY. When false, we do it
51 * American style: MM/DD/YY. Of course, these are all non-RFC822
57 * Table to convert month names to numeric month. We use the
58 * fact that the low order 5 bits of the sum of the 2nd & 3rd
59 * characters of the name is a hash with no collisions for the 12
60 * valid month names. (The mask to 5 bits maps any combination of
61 * upper and lower case into the same hash value).
63 static int month_map[] = {
95 * Same trick for day-of-week using the hash function
98 static int day_map[] = {
112 #define SETDAY { tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)];\
113 tw.tw_flags &= ~TW_SDAY; tw.tw_flags |= TW_SEXP;\
115 #define SETMONTH { tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; gotdate++;\
118 #define CVT1OR2 (i=(*cp++ - '0'), isdigit(*cp)? i*10 + (*cp++ - '0') : i)
119 #define CVT2 ((cp[0] - '0')*10 + (cp[1] - '0'))
120 #define CVT4 ((((cp[0] - '0')*10 + (cp[1] - '0'))*10 + \
121 (cp[2] - '0'))*10 + (cp[3] - '0'))
122 #define SKIPD { while ( !isdigit(*cp++) ) ; --cp; }
123 #define EXPZONE { tw.tw_flags &= ~TW_SZONE; tw.tw_flags |= TW_SZEXP; }
124 #define ZONE(x) { tw.tw_zone=(x); EXPZONE; }
125 #define ZONED(x) { ZONE(x); tw.tw_flags |= TW_DST; }
126 #define LC(c) (isupper (c) ? tolower (c) : (c))
129 # ifdef TIME_WITH_SYS_TIME
130 # include <sys/time.h>
133 # ifdef HAVE_SYS_TIME_H
134 # include <sys/time.h>
141 zonehack (struct tws *tw)
143 register struct tm *tm;
145 if (dmktime (tw) == (time_t) -1)
148 tm = localtime (&tw->tw_clock);
150 tw->tw_flags |= TW_DST;
159 dparsetime (char *str)
162 static struct tws tw;
164 register int gotdate = 0;
167 #ifdef HAVE_TM_GMTOFF
173 # endif /* not HAVE_TZSET */
174 #endif /* HAVE_TM_GMTOFF */
178 /* Zero out the struct. */
179 memset( (char *) &tw, 0, sizeof(tw));
181 /* Set default time zone. */
182 #ifdef HAVE_TM_GMTOFF
184 tm = localtime(&clock);
185 tw.tw_zone = tm->tm_gmtoff / 60;
186 if (tm->tm_isdst) /* if DST is in effect */
187 tw.tw_zone -= 60; /* reset to normal offset */
191 tw.tw_zone = -(timezone / 60);
194 tw.tw_zone = -tb.timezone;
195 # endif /* HAVE_TZSET */
196 #endif /* HAVE_TM_GMTOFF */
198 while (isspace(*str))
201 switch (cp = str, *cp ? lex_string( &str, start_cond) : 0) {
204 if (!gotdate || tw.tw_year == 0)
205 return (struct tws *)0;
208 if (tw.tw_year == 0) {
209 /* Set default year. */
211 tw.tw_year = localtime(&tclock)->tm_year + 1900;
212 } else if (tw.tw_year < 100) {
213 /* assume no 2-digit years > 1999 */
224 {D}(("-"{D}"-")|("/"{D}"/")){D}?{d}{d}{w} {
226 /* European: DD/MM/YY */
227 tw.tw_mday = CVT1OR2;
229 tw.tw_mon = CVT1OR2 - 1;
231 /* American: MM/DD/YY */
232 tw.tw_mon = CVT1OR2 - 1;
234 tw.tw_mday = CVT1OR2;
237 for (i = 0; isdigit(*cp); )
238 i = i*10 + (*cp++ - '0');
244 tw.tw_mday = CVT1OR2; cp++;
245 tw.tw_mon = CVT1OR2 - 1;
247 tw.tw_mon = CVT1OR2 - 1; cp++;
248 tw.tw_mday = CVT1OR2;
252 {D}{w}(-)?{w}{MONTH}{w}(-)?{w}{D}?{d}{d}({W}at)?{w} {
253 tw.tw_mday = CVT1OR2;
254 while ( !isalpha(*cp++) )
257 for (i = 0; isdigit(*cp); )
258 i = i*10 + (*cp++ - '0');
261 {D}"-"?{MONTH}({W}at)?{w} {
262 tw.tw_mday = CVT1OR2;
263 while ( ! isalpha( *cp++ ) )
267 {MONTH}{W}{D}","{W}{D}?{d}{d}{w} {
270 tw.tw_mday = CVT1OR2;
272 for (i = 0; isdigit(*cp); )
273 i = i*10 + (*cp++ - '0');
279 tw.tw_mday = CVT1OR2;
282 {D}:{D}:{D}{W}19[6-9]{d} { /* hack: ctime w/o TZ */
283 tw.tw_hour = CVT1OR2; cp++;
284 tw.tw_min = CVT1OR2; cp++;
287 tw.tw_year = CVT4; cp+=4;
290 tw.tw_hour = CVT1OR2; cp++;
291 tw.tw_min = CVT1OR2; cp++;
296 tw.tw_hour = CVT1OR2; cp++;
301 tw.tw_hour = CVT1OR2; cp++;
302 if (tw.tw_hour == 12)
307 {D}:{D}:{D}{w}am{w} {
308 tw.tw_hour = CVT1OR2; cp++;
309 if (tw.tw_hour == 12)
311 tw.tw_min = CVT1OR2; cp++;
316 tw.tw_hour = CVT1OR2; cp++;
317 if (tw.tw_hour != 12)
322 {D}:{D}:{D}{w}pm{w} {
323 tw.tw_hour = CVT1OR2; cp++;
324 if (tw.tw_hour != 12)
326 tw.tw_min = CVT1OR2; cp++;
330 [0-2]{d}{d}{d}{d}{d}{w} {
331 tw.tw_hour = CVT2; cp+=2;
332 tw.tw_min = CVT2; cp+=2;
333 tw.tw_sec = CVT2; cp+=2;
338 * Luckly, 4 digit times in the range
339 * 1960-1999 aren't legal as hour
342 tw.tw_year = CVT4; cp+=4;
345 if (tw.tw_hour || tw.tw_min
347 tw.tw_year = CVT4; cp+=4;
350 tw.tw_hour = CVT2; cp+=2;
351 tw.tw_min = CVT2; cp+=2;
355 <Z>"-"?ut ZONE(0 * 60);
356 <Z>"-"?gmt ZONE(0 * 60);
357 <Z>"-"?jst ZONE(2 * 60);
358 <Z>"-"?jdt ZONED(2 * 60);
359 <Z>"-"?est ZONE(-5 * 60);
360 <Z>"-"?edt ZONED(-5 * 60);
361 <Z>"-"?cst ZONE(-6 * 60);
362 <Z>"-"?cdt ZONED(-6 * 60);
363 <Z>"-"?mst ZONE(-7 * 60);
364 <Z>"-"?mdt ZONED(-7 * 60);
365 <Z>"-"?pst ZONE(-8 * 60);
366 <Z>"-"?pdt ZONED(-8 * 60);
367 <Z>"-"?nst ZONE(-(3 * 60 + 30));
368 <Z>"-"?ast ZONE(-4 * 60);
369 <Z>"-"?adt ZONED(-4 * 60);
370 <Z>"-"?yst ZONE(-9 * 60);
371 <Z>"-"?ydt ZONED(-9 * 60);
372 <Z>"-"?hst ZONE(-10 * 60);
373 <Z>"-"?hdt ZONED(-10 * 60);
374 <Z>"-"?bst ZONED(-1 * 60);
376 tw.tw_zone = 60 * (('a'-1) - LC(*cp));
380 tw.tw_zone = 60 * ('a' - LC(*cp));
384 tw.tw_zone = 60 * (LC(*cp) - 'm');
387 <Z>"+"[0-1]{d}{d}{d} {
389 tw.tw_zone = ((cp[0] * 10 + cp[1])
390 -('0' * 10 + '0'))*60
391 +((cp[2] * 10 + cp[3])
399 <Z>"-"[0-1]{d}{d}{d} {
401 tw.tw_zone = (('0' * 10 + '0')
402 -(cp[0] * 10 + cp[1]))*60
404 -(cp[2] * 10 + cp[3]));
413 tw.tw_year = CVT4; cp+=4;