From: Marcel Hollerbach Date: Wed, 20 Sep 2017 12:47:49 +0000 (+0200) Subject: time-util: correctly handle the timezone when parsing X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=74b2a31089b0a1a7a1eadf7bbd0873d314e1b432;p=elogind.git time-util: correctly handle the timezone when parsing The timezone was cut off the string once the timezone was not UTC. If it is not UTC but a other timezone that matches tzname[0] or tzname[1], then we can leave it to the impl function to parse that correctly. If not we can just fallback to whatever is the current timezone is in the given t_timezone. This should fix the testuite and tests. --- diff --git a/src/basic/time-util.c b/src/basic/time-util.c index c19c3f60f..3f3ec6890 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -908,8 +908,6 @@ int parse_timestamp(const char *t, usec_t *usec) { 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(); @@ -923,6 +921,8 @@ int parse_timestamp(const char *t, usec_t *usec) { } if (pid == 0) { + bool with_tz = true; + if (setenv("TZ", tz, 1) != 0) { shared->return_value = negative_errno(); _exit(EXIT_FAILURE); @@ -930,7 +930,15 @@ int parse_timestamp(const char *t, usec_t *usec) { 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); }