Gr. strptime is crap for this; it doesn't have a way to require RFC2822 (i.e. English) day/month names, and it doesn't work correctly with %z. */
| 877 | /* Gr. strptime is crap for this; it doesn't have a way to require RFC2822 |
| 878 | (i.e. English) day/month names, and it doesn't work correctly with %z. */ |
| 879 | int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset) |
| 880 | { |
| 881 | struct tm tm; |
| 882 | int tm_gmt; |
| 883 | timestamp_t dummy_timestamp; |
| 884 | int dummy_offset; |
| 885 | |
| 886 | if (!timestamp) |
| 887 | timestamp = &dummy_timestamp; |
| 888 | if (!offset) |
| 889 | offset = &dummy_offset; |
| 890 | |
| 891 | memset(&tm, 0, sizeof(tm)); |
| 892 | tm.tm_year = -1; |
| 893 | tm.tm_mon = -1; |
| 894 | tm.tm_mday = -1; |
| 895 | tm.tm_isdst = -1; |
| 896 | tm.tm_hour = -1; |
| 897 | tm.tm_min = -1; |
| 898 | tm.tm_sec = -1; |
| 899 | *offset = -1; |
| 900 | tm_gmt = 0; |
| 901 | |
| 902 | if (*date == '@' && |
| 903 | !match_object_header_date(date + 1, timestamp, offset)) |
| 904 | return 0; /* success */ |
| 905 | for (;;) { |
| 906 | int match = 0; |
| 907 | unsigned char c = *date; |
| 908 | |
| 909 | /* Stop at end of string or newline */ |
| 910 | if (!c || c == '\n') |
| 911 | break; |
| 912 | |
| 913 | if (isalpha(c)) |
| 914 | match = match_alpha(date, &tm, offset); |
| 915 | else if (isdigit(c)) |
| 916 | match = match_digit(date, &tm, offset, &tm_gmt); |
| 917 | else if ((c == '-' || c == '+') && isdigit(date[1])) |
| 918 | match = match_tz(date, offset); |
| 919 | |
| 920 | if (!match) { |
| 921 | /* BAD CRAP */ |
| 922 | match = 1; |
| 923 | } |
| 924 | |
| 925 | date += match; |
| 926 | } |
| 927 | |
| 928 | /* do not use mktime(), which uses local timezone, here */ |
| 929 | *timestamp = tm_to_time_t(&tm); |
| 930 | if (*timestamp == -1) |
| 931 | return -1; |
| 932 | |
| 933 | if (*offset == -1) { |
| 934 | time_t temp_time; |
| 935 | |
| 936 | /* gmtime_r() in match_digit() may have clobbered it */ |
no test coverage detected