musl: test-time-util: skip parsing back when currently unused timezone is set

This commit is contained in:
Yu Watanabe
2025-11-12 11:40:22 +09:00
parent 8d5b306bb9
commit f8a3ae1be6

View File

@@ -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);