]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
musl: test-time-util: skip parsing back when currently unused timezone is set 39688/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 Nov 2025 02:40:22 +0000 (11:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 Nov 2025 18:13:59 +0000 (03:13 +0900)
src/test/test-time-util.c

index 8f5d8bd5a8d5274c442498b574b7a5d07781ef18..f58be952ef3001509d49ae7771b86fb32d95789c 100644 (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);