| 3160 | } |
| 3161 | |
| 3162 | int64_t parse_date(const char *datestr, int duration) |
| 3163 | { |
| 3164 | const char *p; |
| 3165 | int64_t t; |
| 3166 | struct tm dt; |
| 3167 | int i; |
| 3168 | static const char * const date_fmt[] = { |
| 3169 | "%Y-%m-%d", |
| 3170 | "%Y%m%d", |
| 3171 | }; |
| 3172 | static const char * const time_fmt[] = { |
| 3173 | "%H:%M:%S", |
| 3174 | "%H%M%S", |
| 3175 | }; |
| 3176 | const char *q; |
| 3177 | int is_utc, len; |
| 3178 | char lastch; |
| 3179 | int negative = 0; |
| 3180 | |
| 3181 | #undef time |
| 3182 | time_t now = time(0); |
| 3183 | |
| 3184 | len = strlen(datestr); |
| 3185 | if (len > 0) |
| 3186 | lastch = datestr[len - 1]; |
| 3187 | else |
| 3188 | lastch = '\0'; |
| 3189 | is_utc = (lastch == 'z' || lastch == 'Z'); |
| 3190 | |
| 3191 | memset(&dt, 0, sizeof(dt)); |
| 3192 | |
| 3193 | p = datestr; |
| 3194 | q = NULL; |
| 3195 | if (!duration) { |
| 3196 | if (!strncasecmp(datestr, "now", len)) |
| 3197 | return (int64_t) now * 1000000; |
| 3198 | |
| 3199 | /* parse the year-month-day part */ |
| 3200 | for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) { |
| 3201 | q = small_strptime(p, date_fmt[i], &dt); |
| 3202 | if (q) { |
| 3203 | break; |
| 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | /* if the year-month-day part is missing, then take the |
| 3208 | * current year-month-day time */ |
| 3209 | if (!q) { |
| 3210 | if (is_utc) { |
| 3211 | dt = *gmtime(&now); |
| 3212 | } else { |
| 3213 | dt = *localtime(&now); |
| 3214 | } |
| 3215 | dt.tm_hour = dt.tm_min = dt.tm_sec = 0; |
| 3216 | } else { |
| 3217 | p = q; |
| 3218 | } |
| 3219 |
no test coverage detected