From f8a3ae1be6e19da6800b1b961228cdcb38b36774 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 12 Nov 2025 11:40:22 +0900 Subject: [PATCH] musl: test-time-util: skip parsing back when currently unused timezone is set --- src/test/test-time-util.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c index 8f5d8bd5a8d..f58be952ef3 100644 --- a/src/test/test-time-util.c +++ b/src/test/test-time-util.c @@ -400,6 +400,28 @@ static void test_format_timestamp_impl(usec_t x) { const char *xx = FORMAT_TIMESTAMP(x); ASSERT_NOT_NULL(xx); + /* Because of the timezone change, format_timestamp() may set timezone that is currently unused. + * E.g. Africa/Juba uses EAT since Sat Jan 15 10:00:00 2000 and until Sun Jan 31 20:59:59 2021, but + * now CAT/CAST is used there (see zdump for more details). In such cases, format_timestamp() may set + * the timezone used at the specified time (which happens when built with musl), but it may not match + * the timezone currently used, thus we may not parse back the timestamp. */ + + const char *space; + ASSERT_NOT_NULL(space = strrchr(xx, ' ')); + + const char *tz = space + 1; + if (!streq_ptr(tz, get_tzname(/* dst= */ false)) && + !streq_ptr(tz, get_tzname(/* dst= */ true)) && + parse_gmtoff(tz, NULL) < 0) { + + log_warning("@" USEC_FMT " → %s, timezone '%s' is currently unused, ignoring.", x, xx, tz); + + /* Verify the generated string except for the timezone part. Of course, in most cases, parsed + * time does not match with the input, hence only check if it is parsable. */ + ASSERT_OK(parse_timestamp(strndupa_safe(xx, space - xx), NULL)); + return; + } + usec_t y; ASSERT_OK(parse_timestamp(xx, &y)); const char *yy = FORMAT_TIMESTAMP(y); -- 2.47.3