summary refs log tree commit diff
path: root/time/tst-posixtz.c
blob: 8c36513b0cd7f318a973f3247281f427936c4104 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

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" },
  { 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" },
  { 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" },
};

int
main (void)
{
  int result = 0;
  int cnt;

  for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
    {
      char buf[100];
      struct tm *tmp;

      printf ("TZ = \"%s\", time = %ld => ", tests[cnt].tz, tests[cnt].when);
      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");
	}
    }

  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");
    }

  return result;
}