1 /* Test program from Paul Eggert and Tony Leneis. */
6 static time_t time_t_max;
7 static time_t time_t_min;
9 /* Values we'll use to set the TZ environment variable. */
10 static const char *tz_strings[] =
12 (const char *) 0, "GMT0", "JST-9",
13 "EST+3EDT+2,M10.1.0/00:00:00,M2.3.0/00:00:00"
15 #define N_STRINGS ((int) (sizeof (tz_strings) / sizeof (tz_strings[0])))
17 /* Fail if mktime fails to convert a date in the spring-forward gap.
18 Based on a problem report from Andreas Jaeger. */
20 spring_forward_gap (void)
22 /* glibc (up to about 1998-10-07) failed this test. */
25 /* Use the portable POSIX.1 specification "TZ=PST8PDT,M4.1.0,M10.5.0"
26 instead of "TZ=America/Vancouver" in order to detect the bug even
27 on systems that don't support the Olson extension, or don't have the
28 full zoneinfo tables installed. */
29 setenv ("TZ", "PST8PDT,M4.1.0,M10.5.0", 1);
38 if (mktime (&tm) == (time_t)-1)
43 mktime_test1 (time_t now)
45 struct tm *lt = localtime (&now);
46 if (lt && mktime (lt) != now)
51 mktime_test (time_t now)
54 mktime_test1 ((time_t) (time_t_max - now));
55 mktime_test1 ((time_t) (time_t_min + now));
61 /* Based on code from Ariel Faigon. */
71 if (tm.tm_mon != 2 || tm.tm_mday != 31)
80 tm.tm_year = tm.tm_mon = tm.tm_mday = tm.tm_hour = tm.tm_min = tm.tm_sec = j;
82 if (now != (time_t) -1)
84 struct tm *lt = localtime (&now);
86 && lt->tm_year == tm.tm_year
87 && lt->tm_mon == tm.tm_mon
88 && lt->tm_mday == tm.tm_mday
89 && lt->tm_hour == tm.tm_hour
90 && lt->tm_min == tm.tm_min
91 && lt->tm_sec == tm.tm_sec
92 && lt->tm_yday == tm.tm_yday
93 && lt->tm_wday == tm.tm_wday
94 && ((lt->tm_isdst < 0 ? -1 : 0 < lt->tm_isdst)
95 == (tm.tm_isdst < 0 ? -1 : 0 < tm.tm_isdst))))
106 setenv ("TZ", "America/Sao_Paulo", 1);
107 /* This test makes some buggy mktime implementations loop.
108 Give up after 60 seconds; a mktime slower than that
109 isn't worth using anyway. */
112 for (time_t_max = 1; 0 < time_t_max; time_t_max *= 2)
116 for (time_t_min = -1; (time_t) (time_t_min * 2) < 0; time_t_min *= 2)
118 delta = time_t_max / 997; /* a suitable prime number */
119 for (i = 0; i < N_STRINGS; i++)
122 setenv ("TZ", tz_strings[i], 1);
124 for (t = 0; t <= time_t_max - delta; t += delta)
126 mktime_test ((time_t) 1);
127 mktime_test ((time_t) (60 * 60));
128 mktime_test ((time_t) (60 * 60 * 24));
130 for (j = 1; 0 < j; j *= 2)
132 bigtime_test (j - 1);
135 spring_forward_gap ();
139 #define TEST_FUNCTION do_test ()
140 #include "../test-skeleton.c"