Subject: Re: [PATCH 3/3] mktime: improve tm_isdst heuristic

From: Paul Eggert <[email-masked]>
Date: Sun, 5 Jan 2025 20:50:27 -0800

On 2025-01-05 07:07, Pádraig Brady wrote:
> I notice coreutils CI is now failing in a gnulib test with:
> 
> test-parse-datetime.c:419: assertion 'result.tv_sec == 515107490 - 60 * 
> 60 + (has_leap_seconds ? 13 : 0)' failed
> 
> Adding some extra debug I see that
> result.tv_sec is 1 hour too late (i.e. 515107490).
> 
> This test is related to https://bugs.gnu.org/48085

Yes, it looks like that test is too picky, since Bug#48085 is about 
parse_datetime failing rather than about a particular value. Although I 
could not reproduce the test failure on either Fedora 41 or Ubuntu 24.10 
I installed the attached patch, which I hope fixes things for the 
coreutils CI (for which I don't know the build+run environment).

From e264521aaa0558935a2959f899db2a988fa479ca Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Sun, 5 Jan 2025 20:44:22 -0800
Subject: [PATCH] parse-datetime-tests: port to Gnulib mktime
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Problem reported by Pádraig Brady in:
https://lists.gnu.org/r/bug-gnulib/2025-01/msg00040.html
* tests/test-parse-datetime.c (main): Allow both pedantic and
naive interpretation of "now - 35 years", since the main point of
the test introfuced to fix <https://bugs.gnu.org/48085> was that
parse_datetime shouldn’t fail.
---
 ChangeLog                   |  8 ++++++++
 tests/test-parse-datetime.c | 10 ++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6ee180d284..d9819dbc50 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2025-01-05  Paul Eggert  <[email-masked]>
 
+	parse-datetime-tests: port to Gnulib mktime
+	Problem reported by Pádraig Brady in:
+	https://lists.gnu.org/r/bug-gnulib/2025-01/msg00040.html
+	* tests/test-parse-datetime.c (main): Allow both pedantic and
+	naive interpretation of "now - 35 years", since the main point of
+	the test introfuced to fix <https://bugs.gnu.org/48085> was that
+	parse_datetime shouldn’t fail.
+
 	utimensat: mention Linux kernel bug with CIFS
 	* doc/posix-functions/utimensat.texi (utimensat):
 	Mention Linux kernel bug reported by Bruno Haible in:
diff --git a/tests/test-parse-datetime.c b/tests/test-parse-datetime.c
index a2e9751acd..546b383c55 100644
--- a/tests/test-parse-datetime.c
+++ b/tests/test-parse-datetime.c
@@ -415,8 +415,14 @@ main (_GL_UNUSED int argc, char **argv)
       p = "now - 35 years";
       ASSERT (parse_datetime (&result, p, &now));
       LOG (p, now, result);
-      ASSERT (result.tv_sec
-              == 515107490 - 60 * 60 + (has_leap_seconds ? 13 : 0));
+      /* Allow "now - 35 years" to mean either (a) the naive sense
+         where subtracting 35 years from 2021-04-28 16:24:50 yields
+         1986-04-28 16:24:50, or (b) the pedantic sense where it
+         yields 1986-04-28 15:24:50 (an hour earlier) due to adjusting
+         for the switch from DST in 2021 to standard time in 1986.  */
+      time_t naive = 515107490 + (has_leap_seconds ? 13 : 0);
+      time_t pedantic = naive - 60 * 60;
+      ASSERT (result.tv_sec == naive || result.tv_sec == pedantic);
     }
 
   /* Check that some "next Monday", "last Wednesday", etc. are correct.  */
-- 
2.45.2