@@ -66,6 +66,7 @@ tests := \
tst-gmtime \
tst-itimer \
tst-mktime \
+ tst-mktime-dst-adjust \
tst-mktime2 \
tst-mktime3 \
tst-mktime4 \
new file mode 100644
@@ -0,0 +1,156 @@
+/* Test mktime DST adjustment special cases.
+ Copyright (C) 2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <time.h>
+#include <stdlib.h>
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+ TEST_COMPARE (setenv ("TZ", "UTC", 1), 0);
+
+ {
+ struct tm t =
+ {
+ .tm_year = 124,
+ .tm_mon = 9,
+ .tm_mday = 1,
+ .tm_hour = 9,
+ .tm_min = 20,
+ .tm_sec = 53,
+ .tm_isdst = 1, /* Not actually true. */
+ };
+ TEST_COMPARE (mktime (&t), 1727774453);
+ }
+
+ /* IST used DST at one point, but no longer does. */
+ {
+ char *path = realpath ("../timezone/testdata/IST", NULL);
+ TEST_VERIFY (path != NULL);
+ TEST_COMPARE (setenv ("TZ", path, 1), 0);
+ free (path);
+ }
+
+ {
+ struct tm t =
+ {
+ .tm_year = 124,
+ .tm_mon = 9,
+ .tm_mday = 1,
+ .tm_hour = 9,
+ .tm_min = 20,
+ .tm_sec = 53,
+ .tm_isdst = 0, /* Correct value. */
+ };
+ TEST_COMPARE (mktime (&t), 1727774453 - (int) (5.5 * 3600));
+ TEST_COMPARE (t.tm_gmtoff, (int) (5.5 * 3600));
+ TEST_COMPARE (t.tm_isdst, 0);
+ }
+
+ /* This value is incorrect, but the heuristic ignores historic
+ DST changes. */
+ {
+ struct tm t =
+ {
+ .tm_year = 124,
+ .tm_mon = 9,
+ .tm_mday = 1,
+ .tm_hour = 9,
+ .tm_min = 20,
+ .tm_sec = 53,
+ .tm_isdst = 1, /* Incorrect value. */
+ };
+ TEST_COMPARE (mktime (&t), 1727774453 - (int) (5.5 * 3600));
+ TEST_COMPARE (t.tm_gmtoff, (int) (5.5 * 3600));
+ TEST_COMPARE (t.tm_isdst, 0);
+ }
+
+ /* Test using correct DST. */
+ {
+ struct tm t =
+ {
+ .tm_year = 42,
+ .tm_mon = 9,
+ .tm_mday = 1,
+ .tm_hour = 9,
+ .tm_min = 20,
+ .tm_sec = 53,
+ .tm_isdst = 1, /* Correct value, DST was in effect. */
+ };
+ TEST_COMPARE (mktime (&t), -860015347);
+ TEST_COMPARE (t.tm_gmtoff, (int) (6.5 * 3600));
+ TEST_COMPARE (t.tm_isdst, 1);
+ }
+
+ /* Mismatch: DST incorrectly claimed not in effect. */
+
+ {
+ struct tm t =
+ {
+ .tm_year = 42,
+ .tm_mon = 9,
+ .tm_mday = 1,
+ .tm_hour = 9,
+ .tm_min = 20,
+ .tm_sec = 53,
+ .tm_isdst = 0, /* Incorrect value. */
+ };
+ TEST_COMPARE (mktime (&t), -860015347 + 3600); /* One hour added. */
+ TEST_COMPARE (t.tm_gmtoff, (int) (6.5 * 3600));
+ TEST_COMPARE (t.tm_isdst, 1);
+ }
+
+ /* Test using correct standard time. */
+ {
+ struct tm t =
+ {
+ .tm_year = 42,
+ .tm_mon = 7,
+ .tm_mday = 1,
+ .tm_hour = 9,
+ .tm_min = 20,
+ .tm_sec = 53,
+ .tm_isdst = 0, /* Correct value, standard time in effect. */
+ };
+ TEST_COMPARE (mktime (&t), -865282147);
+ TEST_COMPARE (t.tm_gmtoff, (int) (5.5 * 3600));
+ TEST_COMPARE (t.tm_isdst, 0);
+ }
+
+ /* Test using standard time with mismatch. */
+ {
+ struct tm t =
+ {
+ .tm_year = 42,
+ .tm_mon = 7,
+ .tm_mday = 1,
+ .tm_hour = 9,
+ .tm_min = 20,
+ .tm_sec = 53,
+ .tm_isdst = 1, /* Incorrect value. */
+ };
+ TEST_COMPARE (mktime (&t), -865282147 - 3600); /* One hour subtracted. */
+ TEST_COMPARE (t.tm_gmtoff, (int) (5.5 * 3600));
+ TEST_COMPARE (t.tm_isdst, 0);
+ }
+
+ return 0;
+}
+
+#include <support/test-driver.c>
new file mode 100644
GIT binary patch
literal 285
zcmWHE%1kq2zzf)bvMfL>)Bq&f=kD2c>UNLD8P-CHGgFOLTq+To!N|l6gbWNpH-HKl
zyxl;meIpn+7#N~67<qhrLl}I4*fThULEFI0*nlB~u$}BcgIIxB>^~5w?UK*{(az6b
z8-Qq#8$dM39UvOy7BCHT4~T}kiG`Vk8Rn><3m``Uod$Fi&}lqirwM?Z=7HfnE}%<w
JO|6U#xBzzAN{avh
literal 0
HcmV?d00001
--
2.45.2