|
Last change
on this file was 2036, checked in by bird, 20 years ago |
|
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
|
File size:
1.4 KB
|
| Line | |
|---|
| 1 | #include <stdlib.h>
|
|---|
| 2 | #include <stdio.h>
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 | #include <time.h>
|
|---|
| 5 |
|
|---|
| 6 | int
|
|---|
| 7 | main (void)
|
|---|
| 8 | {
|
|---|
| 9 | struct tm time_str, *tm;
|
|---|
| 10 | time_t t;
|
|---|
| 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 |
|
|---|
| 34 | setenv ("TZ", "EST+5", 1);
|
|---|
| 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 | {
|
|---|
| 49 | printf ("mktime returned %ld, expected %d\n",
|
|---|
| 50 | (long) t, EVENING69);
|
|---|
| 51 | result = 1;
|
|---|
| 52 | }
|
|---|
| 53 | else
|
|---|
| 54 | (void) puts ("Dec 31 1969 EST test passed");
|
|---|
| 55 |
|
|---|
| 56 | setenv ("TZ", "CET-1", 1);
|
|---|
| 57 | t = mktime (&time_str);
|
|---|
| 58 | #define EVENING69_CET (EVENING69 - (5 - -1) * 60 * 60)
|
|---|
| 59 | if (t != EVENING69_CET)
|
|---|
| 60 | {
|
|---|
| 61 | printf ("mktime returned %ld, expected %ld\n",
|
|---|
| 62 | (long) t, (long) EVENING69_CET);
|
|---|
| 63 | result = 1;
|
|---|
| 64 | }
|
|---|
| 65 | else
|
|---|
| 66 | (void) puts ("Dec 31 1969 CET test passed");
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | return result;
|
|---|
| 70 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.