.
[glibc/history.git] / time / tst-strptime2.c
blob73552bb8f825fb780f994778ea93dbb64918c60b
1 #include <limits.h>
2 #include <stdio.h>
3 #include <time.h>
6 static const struct
8 const char *fmt;
9 long int gmtoff;
10 } tests[] =
12 { "1113472456 +1000", 36000 },
13 { "1113472456 -1000", -36000 },
14 { "1113472456 +10", 36000 },
15 { "1113472456 -10", -36000 },
16 { "1113472456 +1030", 37800 },
17 { "1113472456 -1030", -37800 },
18 { "1113472456 +0030", 1800 },
19 { "1113472456 -0030", -1800 },
20 { "1113472456 -1330", LONG_MAX },
21 { "1113472456 +1330", LONG_MAX },
22 { "1113472456 -1060", LONG_MAX },
23 { "1113472456 +1060", LONG_MAX },
24 { "1113472456 1030", LONG_MAX },
26 #define ntests (sizeof (tests) / sizeof (tests[0]))
29 int
30 main (void)
32 int result = 0;
34 for (int i = 0; i < ntests; ++i)
36 struct tm tm;
38 if (strptime (tests[i].fmt, "%s %z", &tm) == NULL)
40 if (tests[i].gmtoff != LONG_MAX)
42 printf ("round %d: strptime unexpectedly failed\n", i);
43 result = 1;
45 continue;
48 if (tm.tm_gmtoff != tests[i].gmtoff)
50 printf ("round %d: tm_gmtoff is %ld\n", i, (long int) tm.tm_gmtoff);
51 result = 1;
55 if (result == 0)
56 puts ("all OK");
58 return 0;