diff options
Diffstat (limited to 'src/basic/time-util.c')
-rw-r--r-- | src/basic/time-util.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index f0b9cc183..fc94c945e 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -861,11 +861,11 @@ parse_usec: } from_tm: - x = mktime_or_timegm(&tm, utc); - if (x < 0) + if (weekday >= 0 && tm.tm_wday != weekday) return -EINVAL; - if (weekday >= 0 && tm.tm_wday != weekday) + x = mktime_or_timegm(&tm, utc); + if (x < 0) return -EINVAL; ret = (usec_t) x * USEC_PER_SEC + x_usec; @@ -895,20 +895,18 @@ typedef struct ParseTimestampResult { } ParseTimestampResult; int parse_timestamp(const char *t, usec_t *usec) { - char *last_space, *timezone = NULL; + char *last_space, *tz = NULL; ParseTimestampResult *shared, tmp; int r; pid_t pid; last_space = strrchr(t, ' '); if (last_space != NULL && timezone_is_valid(last_space + 1)) - timezone = last_space + 1; + tz = last_space + 1; - if (timezone == NULL || endswith_no_case(t, " UTC")) + if (tz == NULL || endswith_no_case(t, " UTC")) return parse_timestamp_impl(t, usec, false); - t = strndupa(t, last_space - t); - shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0); if (shared == MAP_FAILED) return negative_errno(); @@ -922,14 +920,24 @@ int parse_timestamp(const char *t, usec_t *usec) { } if (pid == 0) { - if (setenv("TZ", timezone, 1) != 0) { + bool with_tz = true; + + if (setenv("TZ", tz, 1) != 0) { shared->return_value = negative_errno(); _exit(EXIT_FAILURE); } tzset(); - shared->return_value = parse_timestamp_impl(t, &shared->usec, true); + /* If there is a timezone that matches the tzname fields, leave the parsing to the implementation. + * Otherwise just cut it off */ + with_tz = !STR_IN_SET(tz, tzname[0], tzname[1]); + + /*cut off the timezone if we dont need it*/ + if (with_tz) + t = strndupa(t, last_space - t); + + shared->return_value = parse_timestamp_impl(t, &shared->usec, with_tz); _exit(EXIT_SUCCESS); } |