1560b10ffSOliver Tappe#include <stdlib.h>
2560b10ffSOliver Tappe#include <stdio.h>
3560b10ffSOliver Tappe#include <string.h>
4560b10ffSOliver Tappe#include <time.h>
5560b10ffSOliver Tappe
6560b10ffSOliver Tappeint
7560b10ffSOliver Tappemain (void)
8560b10ffSOliver Tappe{
9560b10ffSOliver Tappe  struct tm time_str, *tm;
10560b10ffSOliver Tappe  time_t t;
11560b10ffSOliver Tappe  char daybuf[20];
12560b10ffSOliver Tappe  int result;
13560b10ffSOliver Tappe
14560b10ffSOliver Tappe  time_str.tm_year = 2001 - 1900;
15560b10ffSOliver Tappe  time_str.tm_mon = 7 - 1;
16560b10ffSOliver Tappe  time_str.tm_mday = 4;
17560b10ffSOliver Tappe  time_str.tm_hour = 0;
18560b10ffSOliver Tappe  time_str.tm_min = 0;
19560b10ffSOliver Tappe  time_str.tm_sec = 1;
20560b10ffSOliver Tappe  time_str.tm_isdst = -1;
21560b10ffSOliver Tappe
22560b10ffSOliver Tappe  if (mktime (&time_str) == -1)
23560b10ffSOliver Tappe    {
24560b10ffSOliver Tappe      (void) puts ("-unknown-");
25560b10ffSOliver Tappe      result = 1;
26560b10ffSOliver Tappe    }
27560b10ffSOliver Tappe  else
28560b10ffSOliver Tappe    {
29560b10ffSOliver Tappe      (void) strftime (daybuf, sizeof (daybuf), "%A", &time_str);
30560b10ffSOliver Tappe      (void) puts (daybuf);
31560b10ffSOliver Tappe      result = strcmp (daybuf, "Wednesday") != 0;
32560b10ffSOliver Tappe    }
33560b10ffSOliver Tappe
34560b10ffSOliver Tappe  setenv ("TZ", "EST+5", 1);
35560b10ffSOliver Tappe#define EVENING69 1 * 60 * 60 + 2 * 60 + 29
36560b10ffSOliver Tappe  t = EVENING69;
37560b10ffSOliver Tappe  tm = localtime (&t);
38560b10ffSOliver Tappe  if (tm == NULL)
39560b10ffSOliver Tappe    {
40560b10ffSOliver Tappe      (void) puts ("localtime returned NULL");
41560b10ffSOliver Tappe      result = 1;
42560b10ffSOliver Tappe    }
43560b10ffSOliver Tappe  else
44560b10ffSOliver Tappe    {
45560b10ffSOliver Tappe      time_str = *tm;
46560b10ffSOliver Tappe      t = mktime (&time_str);
47560b10ffSOliver Tappe      if (t != EVENING69)
48560b10ffSOliver Tappe        {
49560b10ffSOliver Tappe          printf ("mktime returned %ld, expected %d\n",
50560b10ffSOliver Tappe		  (long) t, EVENING69);
51560b10ffSOliver Tappe	  result = 1;
52560b10ffSOliver Tappe        }
53560b10ffSOliver Tappe      else
54560b10ffSOliver Tappe        (void) puts ("Dec 31 1969 EST test passed");
55560b10ffSOliver Tappe
56560b10ffSOliver Tappe      setenv ("TZ", "CET-1", 1);
57560b10ffSOliver Tappe      t = mktime (&time_str);
58560b10ffSOliver Tappe      if (t != (time_t) -1)
59560b10ffSOliver Tappe        {
60560b10ffSOliver Tappe	  printf ("mktime returned %ld, expected -1\n", (long) t);
61560b10ffSOliver Tappe	  result = 1;
62560b10ffSOliver Tappe        }
63560b10ffSOliver Tappe      else
64560b10ffSOliver Tappe        (void) puts ("Dec 31 1969 CET test passed");
65560b10ffSOliver Tappe    }
66560b10ffSOliver Tappe
67560b10ffSOliver Tappe  return result;
68560b10ffSOliver Tappe}
69