1 /* Test program from Paul Eggert and Tony Leneis. */
8 static time_t time_t_max;
9 static time_t time_t_min;
11 /* Values we'll use to set the TZ environment variable. */
12 static const char *tz_strings[] =
14 (const char *) 0, "GMT0", "JST-9",
15 "EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
17 #define N_STRINGS ((int) (sizeof (tz_strings) / sizeof (tz_strings[0])))
19 /* Fail if mktime fails to convert a date in the spring-forward gap.
20 Based on a problem report from Andreas Jaeger. */
22 spring_forward_gap (void)
24 /* glibc (up to about 1998-10-07) failed this test. */
27 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
28 instead of "TZ=America/Vancouver" in order to detect the bug even
29 on systems that don't support the Olson extension, or don't have the
30 full zoneinfo tables installed. */
31 setenv ("TZ", "PST8PDT,M4.1.0,M10.5.0", 1);
40 if (mktime (&tm) == (time_t)-1)
45 mktime_test1 (time_t now)
47 struct tm *lt = localtime (&now);
48 if (lt && mktime (lt) != now)
53 mktime_test (time_t now)
56 mktime_test1 ((time_t) (time_t_max - now));
57 mktime_test1 ((time_t) (time_t_min + now));
63 /* Based on code from Ariel Faigon. */
73 if (tm.tm_mon != 2 || tm.tm_mday != 31)
82 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
85 if (now != (time_t) -1)
87 struct tm *lt = localtime (&now);
89 && lt->tm_year == tm.tm_year
90 && lt->tm_mon == tm.tm_mon
91 && lt->tm_mday == tm.tm_mday
92 && lt->tm_hour == tm.tm_hour
93 && lt->tm_min == tm.tm_min
94 && lt->tm_sec == tm.tm_sec
95 && lt->tm_yday == tm.tm_yday
96 && lt->tm_wday == tm.tm_wday
97 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
98 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
110 setenv ("TZ", "America/Sao_Paulo", 1);
111 /* This test makes some buggy mktime implementations loop.
112 Give up after 60 seconds; a mktime slower than that
113 isn't worth using anyway. */
116 for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
120 for (time_t_min = -1; (time_t) (time_t_min * 2) < 0; time_t_min *= 2)
122 delta = time_t_max / 997; /* a suitable prime number */
123 for (i = 0; i < N_STRINGS; i++)
126 setenv ("TZ", tz_strings[i], 1);
128 for (t = 0; t <= time_t_max - delta; t += delta)
130 mktime_test ((time_t) 1);
131 mktime_test ((time_t) (60 * 60));
132 mktime_test ((time_t) (60 * 60 * 24));
134 for (j = 1; j <= INT_MAX; j *= 2)
136 bigtime_test (j - 1);
139 spring_forward_gap ();
143 #define TEST_FUNCTION do_test ()
144 #include "../test-skeleton.c"