lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <string.h> |
| 4 | #include <time.h> |
| 5 | |
| 6 | struct |
| 7 | { |
| 8 | time_t when; |
| 9 | const char *tz; |
| 10 | const char *result; |
| 11 | } tests[] = |
| 12 | { |
| 13 | { 909312849L, "AEST-10AEDST-11,M10.5.0,M3.5.0", |
| 14 | "1998/10/25 21:54:09 dst=1 zone=AEDST" }, |
| 15 | { 924864849L, "AEST-10AEDST-11,M10.5.0,M3.5.0", |
| 16 | "1999/04/23 20:54:09 dst=0 zone=AEST" }, |
| 17 | { 919973892L, "AEST-10AEDST-11,M10.5.0,M3.5.0", |
| 18 | "1999/02/26 07:18:12 dst=1 zone=AEDST" }, |
| 19 | { 909312849L, "EST+5EDT,M4.1.0/2,M10.5.0/2", |
| 20 | "1998/10/25 05:54:09 dst=0 zone=EST" }, |
| 21 | { 924864849L, "EST+5EDT,M4.1.0/2,M10.5.0/2", |
| 22 | "1999/04/23 06:54:09 dst=1 zone=EDT" }, |
| 23 | { 919973892L, "EST+5EDT,M4.1.0/2,M10.5.0/2", |
| 24 | "1999/02/25 15:18:12 dst=0 zone=EST" }, |
| 25 | }; |
| 26 | |
| 27 | int |
| 28 | main (void) |
| 29 | { |
| 30 | int result = 0; |
| 31 | size_t cnt; |
| 32 | |
| 33 | for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt) |
| 34 | { |
| 35 | char buf[100]; |
| 36 | struct tm *tmp; |
| 37 | |
| 38 | printf ("TZ = \"%s\", time = %ld => ", tests[cnt].tz, tests[cnt].when); |
| 39 | fflush (stdout); |
| 40 | |
| 41 | setenv ("TZ", tests[cnt].tz, 1); |
| 42 | |
| 43 | tmp = localtime (&tests[cnt].when); |
| 44 | |
| 45 | snprintf (buf, sizeof (buf), |
| 46 | "%04d/%02d/%02d %02d:%02d:%02d dst=%d zone=%s", |
| 47 | tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, |
| 48 | tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tmp->tm_isdst, |
| 49 | tzname[tmp->tm_isdst ? 1 : 0]); |
| 50 | |
| 51 | fputs (buf, stdout); |
| 52 | |
| 53 | if (strcmp (buf, tests[cnt].result) == 0) |
| 54 | puts (", OK"); |
| 55 | else |
| 56 | { |
| 57 | result = 1; |
| 58 | puts (", FAIL"); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | setenv ("TZ", "Universal", 1); |
| 63 | localtime (&tests[0].when); |
| 64 | printf ("TZ = \"Universal\" daylight %d tzname = { \"%s\", \"%s\" }", |
| 65 | daylight, tzname[0], tzname[1]); |
| 66 | if (! daylight) |
| 67 | puts (", OK"); |
| 68 | else |
| 69 | { |
| 70 | result = 1; |
| 71 | puts (", FAIL"); |
| 72 | } |
| 73 | |
| 74 | setenv ("TZ", "AEST-10AEDST-11,M10.5.0,M3.5.0", 1); |
| 75 | tzset (); |
| 76 | printf ("TZ = \"AEST-10AEDST-11,M10.5.0,M3.5.0\" daylight %d" |
| 77 | " tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]); |
| 78 | if (daylight |
| 79 | && strcmp (tzname[0], "AEST") == 0 && strcmp (tzname[1], "AEDST") == 0) |
| 80 | puts (", OK"); |
| 81 | else |
| 82 | { |
| 83 | result = 1; |
| 84 | puts (", FAIL"); |
| 85 | } |
| 86 | |
| 87 | return result; |
| 88 | } |