* Parse month, weekday, or timezone name */
| 457 | * Parse month, weekday, or timezone name |
| 458 | */ |
| 459 | static int match_alpha(const char *date, struct tm *tm, int *offset) |
| 460 | { |
| 461 | int i; |
| 462 | |
| 463 | for (i = 0; i < 12; i++) { |
| 464 | int match = match_string(date, month_names[i]); |
| 465 | if (match >= 3) { |
| 466 | tm->tm_mon = i; |
| 467 | return match; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | for (i = 0; i < 7; i++) { |
| 472 | int match = match_string(date, weekday_names[i]); |
| 473 | if (match >= 3) { |
| 474 | tm->tm_wday = i; |
| 475 | return match; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | for (i = 0; i < ARRAY_SIZE(timezone_names); i++) { |
| 480 | int match = match_string(date, timezone_names[i].name); |
| 481 | if (match >= 3 || match == strlen(timezone_names[i].name)) { |
| 482 | int off = timezone_names[i].offset; |
| 483 | |
| 484 | /* This is bogus, but we like summer */ |
| 485 | off += timezone_names[i].dst; |
| 486 | |
| 487 | /* Only use the tz name offset if we don't have anything better */ |
| 488 | if (*offset == -1) |
| 489 | *offset = 60*off; |
| 490 | |
| 491 | return match; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | if (match_string(date, "PM") == 2) { |
| 496 | tm->tm_hour = (tm->tm_hour % 12) + 12; |
| 497 | return 2; |
| 498 | } |
| 499 | |
| 500 | if (match_string(date, "AM") == 2) { |
| 501 | tm->tm_hour = (tm->tm_hour % 12) + 0; |
| 502 | return 2; |
| 503 | } |
| 504 | |
| 505 | /* ISO-8601 allows yyyymmDD'T'HHMMSS, with less precision */ |
| 506 | if (*date == 'T' && isdigit(date[1]) && tm->tm_hour == -1) { |
| 507 | tm->tm_min = tm->tm_sec = 0; |
| 508 | return 1; |
| 509 | } |
| 510 | |
| 511 | /* BAD CRAP */ |
| 512 | return skip_alpha(date); |
| 513 | } |
| 514 | |
| 515 | static int set_date(int year, int month, int day, struct tm *now_tm, time_t now, struct tm *tm) |
| 516 | { |
no test coverage detected