1998-10-26 11:11:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2017-02-16 22:31:42 +00:00
|
|
|
#include <stdint.h>
|
1998-10-26 11:11:28 +00:00
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
time_t when;
|
|
|
|
const char *tz;
|
|
|
|
const char *result;
|
|
|
|
} tests[] =
|
|
|
|
{
|
|
|
|
{ 909312849L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
|
|
|
|
"1998/10/25 21:54:09 dst=1 zone=AEDST" },
|
|
|
|
{ 924864849L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
|
|
|
|
"1999/04/23 20:54:09 dst=0 zone=AEST" },
|
2002-03-12 07:50:21 +00:00
|
|
|
{ 919973892L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
|
|
|
|
"1999/02/26 07:18:12 dst=1 zone=AEDST" },
|
|
|
|
{ 909312849L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
|
|
|
|
"1998/10/25 05:54:09 dst=0 zone=EST" },
|
2009-03-10 15:23:46 +00:00
|
|
|
{ 909312849L, "EST5EDT,M4.1.0/2,M10.5.0/2",
|
|
|
|
"1998/10/25 05:54:09 dst=0 zone=EST" },
|
|
|
|
{ 909312849L, "<EST5>5EDT,M4.1.0/2,M10.5.0/2",
|
|
|
|
"1998/10/25 05:54:09 dst=0 zone=EST5" },
|
2002-03-12 07:50:21 +00:00
|
|
|
{ 924864849L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
|
|
|
|
"1999/04/23 06:54:09 dst=1 zone=EDT" },
|
|
|
|
{ 919973892L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
|
|
|
|
"1999/02/25 15:18:12 dst=0 zone=EST" },
|
1998-10-26 11:11:28 +00:00
|
|
|
};
|
|
|
|
|
2014-11-05 09:54:08 +00:00
|
|
|
static int
|
|
|
|
do_test (void)
|
1998-10-26 11:11:28 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
2002-09-24 04:24:25 +00:00
|
|
|
size_t cnt;
|
1998-10-26 11:11:28 +00:00
|
|
|
|
|
|
|
for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
|
|
|
|
{
|
|
|
|
char buf[100];
|
|
|
|
struct tm *tmp;
|
|
|
|
|
2014-12-19 22:04:35 +00:00
|
|
|
printf ("TZ = \"%s\", time = %jd => ", tests[cnt].tz,
|
|
|
|
(intmax_t) tests[cnt].when);
|
1998-10-26 11:11:28 +00:00
|
|
|
fflush (stdout);
|
|
|
|
|
|
|
|
setenv ("TZ", tests[cnt].tz, 1);
|
|
|
|
|
|
|
|
tmp = localtime (&tests[cnt].when);
|
|
|
|
|
|
|
|
snprintf (buf, sizeof (buf),
|
|
|
|
"%04d/%02d/%02d %02d:%02d:%02d dst=%d zone=%s",
|
|
|
|
tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
|
|
|
|
tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tmp->tm_isdst,
|
|
|
|
tzname[tmp->tm_isdst ? 1 : 0]);
|
|
|
|
|
|
|
|
fputs (buf, stdout);
|
|
|
|
|
|
|
|
if (strcmp (buf, tests[cnt].result) == 0)
|
|
|
|
puts (", OK");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
puts (", FAIL");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-12 07:50:21 +00:00
|
|
|
setenv ("TZ", "Universal", 1);
|
|
|
|
localtime (&tests[0].when);
|
|
|
|
printf ("TZ = \"Universal\" daylight %d tzname = { \"%s\", \"%s\" }",
|
|
|
|
daylight, tzname[0], tzname[1]);
|
|
|
|
if (! daylight)
|
|
|
|
puts (", OK");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
puts (", FAIL");
|
|
|
|
}
|
|
|
|
|
|
|
|
setenv ("TZ", "AEST-10AEDST-11,M10.5.0,M3.5.0", 1);
|
|
|
|
tzset ();
|
|
|
|
printf ("TZ = \"AEST-10AEDST-11,M10.5.0,M3.5.0\" daylight %d"
|
|
|
|
" tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
|
|
|
|
if (daylight
|
|
|
|
&& strcmp (tzname[0], "AEST") == 0 && strcmp (tzname[1], "AEDST") == 0)
|
|
|
|
puts (", OK");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
puts (", FAIL");
|
|
|
|
}
|
|
|
|
|
2009-03-10 15:23:46 +00:00
|
|
|
setenv ("TZ", "<AB1>-10<AB2>-11,M10.5.0,M3.5.0", 1);
|
|
|
|
tzset ();
|
|
|
|
printf ("TZ = \"<AB1>-10<AB2>-11,M10.5.0,M3.5.0\" daylight %d"
|
|
|
|
" tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
|
|
|
|
if (daylight
|
|
|
|
&& strcmp (tzname[0], "AB1") == 0 && strcmp (tzname[1], "AB2") == 0)
|
|
|
|
puts (", OK");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
puts (", FAIL");
|
|
|
|
}
|
|
|
|
|
|
|
|
setenv ("TZ", "<BB1>-10", 1);
|
|
|
|
tzset ();
|
|
|
|
printf ("TZ = \"<BB1>-10\" daylight %d"
|
|
|
|
" tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
|
|
|
|
if (daylight == 0
|
|
|
|
&& strcmp (tzname[0], "BB1") == 0 && strcmp (tzname[1], "BB1") == 0)
|
|
|
|
puts (", OK");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = 1;
|
|
|
|
puts (", FAIL");
|
|
|
|
}
|
|
|
|
|
1998-10-26 11:11:28 +00:00
|
|
|
return result;
|
|
|
|
}
|
2014-11-05 09:54:08 +00:00
|
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
|
|
#include "../test-skeleton.c"
|