14 DAY ({sun}|{mon}|{tue}|{wed}|{thu}|{fri}|{sat})
29 MONTH ({jan}|{feb}|{mar}|{apr}|{may}|{jun}|{jul}|{aug}|{sep}|{oct}|{nov}|{dec})
36 /* dtimep.lex - routines to do ``ARPA-style'' time parsing
39 --- ------- --- -------------------------------------------------------------
40 01B 15nov86 JP Thouroughly hacked by Jef Poskanzer.
41 01A ??????? MTR Original version from the MH 6.5 distribution, courtesy
48 #include <sys/types.h>
54 #include <sys/timeb.h>
60 extern char *tzname[];
64 * Table to convert month names to numeric month. We use the
65 * fact that the low order 5 bits of the sum of the 2nd & 3rd
66 * characters of the name is a hash with no collisions for the 12
67 * valid month names. (The mask to 5 bits maps any combination of
68 * upper and lower case into the same hash value).
70 static int month_map[] = {
101 * Same trick for day-of-week using the hash function
102 * (c1 & 7) + (c2 & 4)
104 static int day_map[] = {
117 #define SETDAY tw.tw_wday= day_map[(cp[0] & 7) + (cp[1] & 4)];\
118 tw.tw_flags |= TW_SEXP;\
120 #define SETMONTH tw.tw_mon = month_map[(cp[0] + cp[1]) & 0x1f]; gotdate++;\
123 #define CVT1OR2 (i=(*cp++ - '0'), isdigit(*cp)? i*10 + (*cp++ - '0') : i)
124 #define CVT2 ( (*cp++ - '0')*10 + (*cp++ - '0') )
125 #define CVT3 ( ( (*cp++ - '0')*10 + (*cp++ - '0') )*10 + (*cp++ - '0') )
126 #define CVT4 ( ( ( (*cp++ - '0')*10 + (*cp++ - '0') )*10 + (*cp++ - '0') )*10 + (*cp++ - '0') )
127 #define SKIPD while ( ! isdigit( *cp++ ) ) ; --cp;
128 #define ZONE(x) tw.tw_zone=(x);
129 #define ZONED(x) tw.tw_zone=(x); tw.tw_flags |= TW_DST;
130 #define LC(c) (isupper( c ) ? tolower( c ) : ( c ))
139 static struct tws tw;
141 register int gotdate = 0;
149 /* Zero out the struct. */
150 bzero( (char *) &tw, sizeof tw );
152 /* Set default time zone. */
155 tw.tw_zone = -tb.timezone;
158 tw.tw_zone = -(timezone / 60);
162 switch ( cp = str, lex_string( &str, start_cond ) )
167 tw.tw_flags |= TW_JUNK;
170 if ( tw.tw_year == 0 )
172 /* Set default year. */
174 tw.tw_year = localtime( &clock ) -> tm_year;
180 "("{DAY}")"(","?) cp++, SETDAY;
182 {D}"/"{D}"/"{D}?{d}{d}{w} {
184 tw.tw_mday = CVT1OR2; cp++;
185 tw.tw_mon = CVT1OR2 - 1; cp++;
187 tw.tw_mon = CVT1OR2 - 1; cp++;
188 tw.tw_mday = CVT1OR2; cp++;
190 for ( i = 0; isdigit( *cp ); )
191 i = i * 10 + (*cp++ - '0');
197 tw.tw_mday = CVT1OR2; cp++;
198 tw.tw_mon = CVT1OR2 - 1;
200 tw.tw_mon = CVT1OR2 - 1; cp++;
201 tw.tw_mday = CVT1OR2;
205 {D}"-"?{MONTH}"-"?{D}?{d}{d}({W}at)?{w} |
206 {D}" "{MONTH}" "{D}?{d}{d}({W}at)?{w} {
207 tw.tw_mday = CVT1OR2;
208 while ( ! isalpha( *cp++ ) )
211 for ( i = 0; isdigit( *cp ); )
212 i = i * 10 + (*cp++ - '0');
216 {D}"-"?{MONTH}({W}at)?{w} {
217 tw.tw_mday = CVT1OR2;
218 while ( ! isalpha( *cp++ ) )
223 {MONTH}{W}{D}","{W}{D}?{d}{d}{w} {
226 tw.tw_mday = CVT1OR2;
228 for ( i = 0; isdigit( *cp ); )
229 i = i * 10 + (*cp++ - '0');
236 tw.tw_mday = CVT1OR2;
240 {D}:{D}:{D}({w}am)?{w} {
241 tw.tw_hour = CVT1OR2; cp++;
242 tw.tw_min = CVT1OR2; cp++;
246 {D}:{D}:{D}{w}pm{w} {
247 tw.tw_hour = CVT1OR2 + 12; cp++;
248 tw.tw_min = CVT1OR2; cp++;
253 tw.tw_hour = CVT1OR2; cp++;
258 tw.tw_hour = CVT1OR2 + 12; cp++;
262 [0-2]{d}{d}{d}{d}{d}{w} {
263 tw.tw_hour = CVT1OR2;
269 tw.tw_hour = CVT1OR2;
273 <Z>"-"?ut ZONE(0 * 60);
274 <Z>"-"?gmt ZONE(0 * 60);
275 <Z>"-"?jst ZONE(2 * 60);
276 <Z>"-"?jdt ZONED(2 * 60);
277 <Z>"-"?est ZONE(-5 * 60);
278 <Z>"-"?edt ZONED(-5 * 60);
279 <Z>"-"?cst ZONE(-6 * 60);
280 <Z>"-"?cdt ZONED(-6 * 60);
281 <Z>"-"?mst ZONE(-7 * 60);
282 <Z>"-"?mdt ZONED(-7 * 60);
283 <Z>"-"?pst ZONE(-8 * 60);
284 <Z>"-"?pdt ZONED(-8 * 60);
285 <Z>"-"?nst ZONE(-(3 * 60 + 30));
286 <Z>"-"?ast ZONE(-4 * 60);
287 <Z>"-"?adt ZONED(-4 * 60);
288 <Z>"-"?yst ZONE(-9 * 60);
289 <Z>"-"?ydt ZONED(-9 * 60);
290 <Z>"-"?hst ZONE(-10 * 60);
291 <Z>"-"?hdt ZONED(-10 * 60);
292 <Z>"-"?bst ZONED(-1 * 60);
293 <Z>[a-i] tw.tw_zone = 60 * (('a'-1) - LC (*cp));
294 <Z>[k-m] tw.tw_zone = 60 * ('a' - LC (*cp));
295 <Z>[n-y] tw.tw_zone = 60 * (LC (*cp) - 'm');
296 <Z>"+"[0-1]{d}{d}{d} {
298 tw.tw_zone = ((cp[0] * 10 + cp[1])
299 -('0' * 10 + '0'))*60
300 +((cp[2] * 10 + cp[3])
307 <Z>"-"[0-1]{d}{d}{d} {
309 tw.tw_zone = (('0' * 10 + '0')
310 -(cp[0] * 10 + cp[1]))*60
312 -(cp[2] * 10 + cp[3]));
330 register struct tws *tw;
332 register struct tm *tm;
334 if ( twclock( tw ) == -1L )
337 tm = localtime( &tw -> tw_clock );
338 if ( tm -> tm_isdst )
340 tw -> tw_flags |= TW_DST;