summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2022-02-19 15:04:43 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2022-02-19 15:28:11 -0800
commit06b2e943be39284783ff81ac6c9503200f41dba3 (patch)
tree05f59fa34157a79ebaef39a3433838da9b7d5540 /tests
parent9f48fb992a3d7e96610c4ce8be969cff2d61a01b (diff)
downloadgnulib-06b2e943be39284783ff81ac6c9503200f41dba3.tar.gz
mktime: improve heuristic for ca-1986 Indiana DST
Problem reported by Mark Krenz <https://bugs.gnu.org/48085>. * lib/mktime.c (__mktime_internal): Be more generous about accepting arguments with the wrong value of tm_isdst, by falling back to a one-hour DST difference if we find no nearby DST that is unusual. This fixes a problem where "1986-04-28 00:00 EDT" was rejected when TZ="America/Indianapolis" because the nearest DST timestamp occurred in 1970, a temporal distance too great for the old heuristic. This also also narrows the search a bit, which is a minor performance win. * m4/mktime.m4 (gl_FUNC_MKTIME_WORKS): Check for putenv failures and for Bug#48085. * tests/test-parse-datetime.c (main): Test for setenv failures and for Bug#48085.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-parse-datetime.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/tests/test-parse-datetime.c b/tests/test-parse-datetime.c
index 1e7955bc96..4310ee8a3d 100644
--- a/tests/test-parse-datetime.c
+++ b/tests/test-parse-datetime.c
@@ -126,7 +126,7 @@ main (_GL_UNUSED int argc, char **argv)
should disable any leap second support. Otherwise, there will be
a problem with glibc on sites that default to leap seconds; see
<https://bugs.gnu.org/12206>. */
- setenv ("TZ", "EST5EDT,M3.2.0,M11.1.0", 1);
+ ASSERT (setenv ("TZ", "EST5EDT,M3.2.0,M11.1.0", 1) == 0);
gmtoff = gmt_offset (ref_time);
@@ -375,8 +375,25 @@ main (_GL_UNUSED int argc, char **argv)
ASSERT (result.tv_sec == result2.tv_sec
&& result.tv_nsec == result2.tv_nsec);
+ /* If this platform has TZDB, check for GNU Bug#48085. */
+ ASSERT (setenv ("TZ", "America/Indiana/Indianapolis", 1) == 0);
+ now.tv_sec = 1619641490;
+ now.tv_nsec = 0;
+ struct tm *tm = localtime (&now.tv_sec);
+ if (tm && tm->tm_year == 2021 - 1900 && tm->tm_mon == 4 - 1
+ && tm->tm_mday == 28 && tm->tm_hour == 16 && tm->tm_min == 24
+ && 0 < tm->tm_isdst)
+ {
+ int has_leap_seconds = tm->tm_sec != now.tv_sec % 60;
+ 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));
+ }
+
/* Check that some "next Monday", "last Wednesday", etc. are correct. */
- setenv ("TZ", "UTC0", 1);
+ ASSERT (setenv ("TZ", "UTC0", 1) == 0);
for (i = 0; day_table[i]; i++)
{
unsigned int thur2 = 7 * 24 * 3600; /* 2nd thursday */