]> git.ipfire.org Git - thirdparty/glibc.git/blame - time/tst-mktime.c
Installed-header hygiene (BZ#20366): time.h types.
[thirdparty/glibc.git] / time / tst-mktime.c
CommitLineData
9813858f 1#include <stdlib.h>
354e6102
UD
2#include <stdio.h>
3#include <string.h>
4#include <time.h>
5
29955b5d
AS
6static int
7do_test (void)
354e6102 8{
78575a84
UD
9 struct tm time_str, *tm;
10 time_t t;
354e6102
UD
11 char daybuf[20];
12 int result;
13
14 time_str.tm_year = 2001 - 1900;
15 time_str.tm_mon = 7 - 1;
16 time_str.tm_mday = 4;
17 time_str.tm_hour = 0;
18 time_str.tm_min = 0;
19 time_str.tm_sec = 1;
20 time_str.tm_isdst = -1;
21
22 if (mktime (&time_str) == -1)
23 {
24 (void) puts ("-unknown-");
25 result = 1;
26 }
27 else
28 {
29 (void) strftime (daybuf, sizeof (daybuf), "%A", &time_str);
30 (void) puts (daybuf);
31 result = strcmp (daybuf, "Wednesday") != 0;
32 }
33
9813858f 34 setenv ("TZ", "EST+5", 1);
78575a84
UD
35#define EVENING69 1 * 60 * 60 + 2 * 60 + 29
36 t = EVENING69;
37 tm = localtime (&t);
38 if (tm == NULL)
39 {
40 (void) puts ("localtime returned NULL");
41 result = 1;
42 }
43 else
44 {
45 time_str = *tm;
46 t = mktime (&time_str);
47 if (t != EVENING69)
48 {
9813858f 49 printf ("mktime returned %ld, expected %d\n",
78575a84
UD
50 (long) t, EVENING69);
51 result = 1;
52 }
53 else
54 (void) puts ("Dec 31 1969 EST test passed");
55
9813858f 56 setenv ("TZ", "CET-1", 1);
78575a84 57 t = mktime (&time_str);
e507cc56
RM
58#define EVENING69_CET (EVENING69 - (5 - -1) * 60 * 60)
59 if (t != EVENING69_CET)
78575a84 60 {
e507cc56
RM
61 printf ("mktime returned %ld, expected %ld\n",
62 (long) t, (long) EVENING69_CET);
78575a84
UD
63 result = 1;
64 }
65 else
66 (void) puts ("Dec 31 1969 CET test passed");
67 }
68
354e6102
UD
69 return result;
70}
29955b5d
AS
71
72#define TEST_FUNCTION do_test ()
73#include "../test-skeleton.c"