-static int
-ll_parse_date(
- int type,
- char * text)
-{
- time_t now;
- struct tm *t;
- int y=2000, m=0, d=1, h=0, mi=0, s=0;
- int ret;
-
- now = time((time_t *)NULL);
- t = localtime(&now);
- if (t) {
- y = 1900+t->tm_year;
- m = t->tm_mon+1;
- d = t->tm_mday;
- }
- switch(type) {
- case 1:
- if (sscanf(text, "---%d", &d) != 1) {
- yyerror("invalid date");
- }
- break;
- case 2:
- if (sscanf(text, "--%d-%d", &m, &d) != 2) {
- yyerror("invalid date");
- }
- break;
- case 3:
- if (sscanf(text, "%d-%d-%d", &y, &m, &d) != 3) {
- yyerror("invalid date");
- }
- break;
- case 4:
- if (sscanf(text, "%d-%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi, &s) != 6) {
- yyerror("invalid date");
- }
- break;
- case 5:
- if (sscanf(text, "%d-%d-%d-%d-%d", &y, &m, &d, &h, &mi) != 5) {
- yyerror("invalid date");
- }
- break;
- }
-
- ret = PATH; /* cause a parse error */
- if(y < 70) {
- y += 2000;
- } else if(y < 100) {
- y += 1900;
- }
- if(y < 1000 || y > 9999) {
- yyerror("invalid year");
- } else if(m < 1 || m > 12) {
- yyerror("invalid month");
- } else if(d < 1 || d > 31) {
- yyerror("invalid day");
- } else if(h < 0 || h > 24) {
- yyerror("invalid hour");
- } else if(mi < 0 || mi > 59) {
- yyerror("invalid minute");
- } else if(s < 0 || s > 59) {
- yyerror("invalid second");
- } else if(type < 4) {
- yylval.strval = alloc(DATE_ALLOC_SIZE);
- snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d", y, m, d);
- ret = DATE;
- } else {
- yylval.strval = alloc(DATE_ALLOC_SIZE);
- snprintf(yylval.strval, DATE_ALLOC_SIZE, "%04d-%02d-%02d-%02d-%02d-%02d", y, m, d, h, mi, s);
- ret = DATE;
- }
- return ret;
-}