Wed Jan 24 04:18:36 1996 Paul Eggert <eggert@twinsun.com>
[glibc.git] / time / test_time.c
bloba090d93db45c2a0d654857613077b4eb571fecbd
1 /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 #include <ansidecl.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <time.h>
25 int
26 DEFUN(main, (argc, argv), int argc AND char **argv)
28 time_t t;
29 register struct tm *tp;
30 struct tm tbuf;
31 int lose = 0;
33 --argc;
34 ++argv;
38 char buf[BUFSIZ];
39 if (argc > 0)
41 static char buf[BUFSIZ];
42 sprintf(buf, "TZ=%s", *argv);
43 if (putenv(buf))
45 puts("putenv failed.");
46 lose = 1;
48 else
49 puts (buf);
51 tzset();
52 tbuf.tm_year = 72;
53 tbuf.tm_mon = 0;
54 tbuf.tm_mday = 31;
55 tbuf.tm_hour = 6;
56 tbuf.tm_min = 14;
57 tbuf.tm_sec = 50;
58 tbuf.tm_isdst = -1;
59 doit:;
60 t = mktime(&tbuf);
61 if (t == (time_t) -1)
63 puts("mktime() failed?");
64 lose = 1;
66 tp = localtime(&t);
67 if (tp == NULL)
69 puts("localtime() failed.");
70 lose = 1;
72 else if (strftime(buf, sizeof(buf), "%a %b %d %X %Z %Y", tp) == 0)
74 puts("strftime() failed.");
75 lose = 1;
77 else
78 puts(buf);
79 if (tbuf.tm_year == 101)
81 tbuf.tm_year = 97;
82 tbuf.tm_mon = 0;
83 goto doit;
85 ++argv;
86 } while (--argc > 0);
89 #define SIZE 256
90 char buffer[SIZE];
91 time_t curtime;
92 struct tm *loctime;
94 curtime = time (NULL);
96 loctime = localtime (&curtime);
98 fputs (asctime (loctime), stdout);
100 strftime (buffer, SIZE, "Today is %A, %B %d.\n", loctime);
101 fputs (buffer, stdout);
102 strftime (buffer, SIZE, "The time is %I:%M %p.\n", loctime);
103 fputs (buffer, stdout);
105 loctime->tm_year = 72;
106 loctime->tm_mon = 8;
107 loctime->tm_mday = 12;
108 loctime->tm_hour = 20;
109 loctime->tm_min = 49;
110 loctime->tm_sec = 05;
111 curtime = mktime (loctime);
112 strftime (buffer, SIZE, "%D %T was %w the %jth.\n", loctime);
113 fputs (buffer, stdout);
116 return (lose ? EXIT_FAILURE : EXIT_SUCCESS);