View | Details | Raw Unified | Return to bug 14151
Collapse All | Expand All

(-)date/date.1 (-39 / +45 lines)
Lines 35-41 Link Here
35
.\"     @(#)date.1	8.3 (Berkeley) 4/28/95
35
.\"     @(#)date.1	8.3 (Berkeley) 4/28/95
36
.\" $FreeBSD: src/bin/date/date.1,v 1.31 1999/08/27 23:13:58 peter Exp $
36
.\" $FreeBSD: src/bin/date/date.1,v 1.31 1999/08/27 23:13:58 peter Exp $
37
.\"
37
.\"
38
.Dd November 17, 1993
38
.Dd April 28, 1995
39
.Dt DATE 1
39
.Dt DATE 1
40
.Os
40
.Os
41
.Sh NAME
41
.Sh NAME
Lines 49-74 Link Here
49
.Op Fl t Ar minutes_west
49
.Op Fl t Ar minutes_west
50
.Op Fl v Ns Ar [+|-]val Ns Op ymwdHMS
50
.Op Fl v Ns Ar [+|-]val Ns Op ymwdHMS
51
.Ar ...
51
.Ar ...
52
.Op Fl f Ar fmt Ar date | [[[[yy]mm]dd]HH]MM[\&.ss]
52
.Op Fl f Ar fmt Ar date | [[[[[cc]yy]mm]dd]HH]MM[\&.ss]
53
.Op Cm + Ns Ar format
53
.Op Cm + Ns Ar format
54
.Sh DESCRIPTION
54
.Sh DESCRIPTION
55
.Nm Date
55
When invoked without arguments, the
56
displays the current date and time when invoked without arguments.
56
.Nm
57
Providing arguments will format the date and time in a user-defined
57
utility displays the current date and time.
58
way or set the date.
58
Otherwise, depending on the options specified,
59
Only the superuser may set the date.
59
.Nm
60
will set the date and time or print it in a user-defined way.
61
.Pp
62
Only the super-user may set the date.
60
.Pp
63
.Pp
61
The options are as follows:
64
The options are as follows:
62
.Bl -tag -width Ds
65
.Bl -tag -width Ds
63
.It Fl d
66
.It Fl d Ar dst
64
Set the kernel's value for daylight savings time.
67
Set the kernel's value for daylight saving time.
65
If
68
If
66
.Ar dst
69
.Ar dst
67
is non-zero, future calls
70
is non-zero, future calls
68
to
71
to
69
.Xr gettimeofday 2
72
.Xr gettimeofday 2
70
will return a non-zero
73
will return a non-zero
71
.Ql tz_dsttime  .
74
.Ql tz_dsttime .
72
.It Fl f
75
.It Fl f
73
Use
76
Use
74
.Ar fmt
77
.Ar fmt
Lines 88-94 Link Here
88
.Xr timed 8
91
.Xr timed 8
89
is used to synchronize the clocks on groups of machines.
92
is used to synchronize the clocks on groups of machines.
90
By default, if
93
By default, if
91
.Xr timed
94
.Xr timed 8
92
is running,
95
is running,
93
.Nm
96
.Nm
94
will set the time on all of the machines in the local group.
97
will set the time on all of the machines in the local group.
Lines 97-119 Link Here
97
option stops
100
option stops
98
.Nm
101
.Nm
99
from setting the time for other than the current machine.
102
from setting the time for other than the current machine.
100
.It Fl r
103
.It Fl r Ar seconds
101
Print out the date and time in
104
Print out (in specified format) the date and time represented by
102
.Ar seconds
105
.Ar seconds
103
from the Epoch.
106
from the Epoch.
104
.It Fl t
107
.It Fl t Ar minutes_west
105
Set the kernel's value for minutes west of
108
Set the kernel's value for minutes west of
106
.Tn GMT .
109
.Tn GMT .
107
.Ar Minutes_west
110
.Ar minutes_west
108
specifies the number of minutes returned in
111
specifies the number of minutes returned in
109
.Ql tz_minuteswest  
112
.Ql tz_minuteswest
110
by future calls to
113
by future calls to
111
.Xr gettimeofday 2 .
114
.Xr gettimeofday 2 .
112
.It Fl u
115
.It Fl u
113
Display or set the date in
116
Display or set the date in
114
.Tn UCT
117
.Tn UTC
115
(universal) time.
118
(universal) time.
116
.It Fl v
119
.It Fl v Ns Ar [+|-]val Ns Op ymwdHMS
117
Adjust the second, minute, hour, month day, week day, month or year according to
120
Adjust the second, minute, hour, month day, week day, month or year according to
118
.Ar val .  
121
.Ar val .  
119
If
122
If
Lines 150-159 Link Here
150
Refer to the examples below for further details.
153
Refer to the examples below for further details.
151
.El
154
.El
152
.Pp
155
.Pp
153
An operand with a leading plus (``+'') sign signals a user-defined format
156
An operand with a leading plus sign
157
.Pq Sq +
158
signals a user-defined format
154
string which specifies the format in which to display the date and time.
159
string which specifies the format in which to display the date and time.
155
The format string may contain any of the conversion specifications described
160
The format string may contain any of the conversion specifications described
156
in the 
161
in the
157
.Xr strftime 3
162
.Xr strftime 3
158
manual page, as well as any arbitrary text.
163
manual page, as well as any arbitrary text.
159
A <newline> character is always output after the characters specified by
164
A <newline> character is always output after the characters specified by
Lines 169-192 Link Here
169
.Pp
174
.Pp
170
.Bl -tag -width Ds -compact -offset indent
175
.Bl -tag -width Ds -compact -offset indent
171
.It Ar yy
176
.It Ar yy
172
Year in abbreviated form (e.g. 89 for 1989, 06 for 2006).
177
Year in abbreviated form (for years falling within 1969\(em2068).
178
The format
179
.Ar ccyymmddHHMM
180
is also permitted, for non-ambiguous years.
173
.It Ar mm
181
.It Ar mm
174
Numeric month.
182
Numeric month, a number from 1 to 12.
175
A number from 1 to 12.
176
.It Ar dd
183
.It Ar dd
177
Day, a number from 1 to 31.
184
Day, a number from 1 to 31.
178
.It Ar HH
185
.It Ar HH
179
Hour, a number from 0 to 23.
186
Hour, a number from 0 to 23.
180
.It Ar MM
187
.It Ar MM
181
Minutes, a number from 0 to 59.
188
Minute, a number from 0 to 59.
182
.It Ar .ss
189
.It Ar .SS
183
Seconds, a number from 0 to 61 (59 plus a maximum of two leap seconds).
190
Second, a number from 0 to 61 (59 plus a maximum of two leap seconds).
184
.El
191
.El
185
.Pp
192
.Pp
186
Everything but the minutes is optional.
193
Everything but the minute is optional.
187
.Pp
194
.Pp
188
Time changes for Daylight Saving and Standard time and leap seconds
195
Time changes for daylight saving time, standard time, leap seconds,
189
and years are handled automatically.
196
and leap years are handled automatically.
190
.Sh EXAMPLES
197
.Sh EXAMPLES
191
The command:
198
The command:
192
.Bd -literal -offset indent
199
.Bd -literal -offset indent
Lines 250-258 Link Here
250
.Li "2:32 PM" ,
257
.Li "2:32 PM" ,
251
without modifying the date.
258
without modifying the date.
252
.Sh ENVIRONMENT
259
.Sh ENVIRONMENT
253
The execution of
260
The following environment variables affect the execution of
254
.Nm
261
.Nm date :
255
is affected by the following environment variables:
256
.Bl -tag -width Ds
262
.Bl -tag -width Ds
257
.It Ev TZ
263
.It Ev TZ
258
The timezone to use when displaying dates.
264
The timezone to use when displaying dates.
Lines 268-276 Link Here
268
.Sh FILES
274
.Sh FILES
269
.Bl -tag -width /var/log/messages -compact
275
.Bl -tag -width /var/log/messages -compact
270
.It Pa /var/log/wtmp
276
.It Pa /var/log/wtmp
271
a record of date resets and time changes
277
record of date resets and time changes
272
.It Pa /var/log/messages
278
.It Pa /var/log/messages
273
a record of the user setting the time
279
record of the user setting the time
274
.El
280
.El
275
.Sh SEE ALSO
281
.Sh SEE ALSO
276
.Xr gettimeofday 2 ,
282
.Xr gettimeofday 2 ,
Lines 290-314 Link Here
290
if able to set the local date, but unable to set it globally.
296
if able to set the local date, but unable to set it globally.
291
.Pp
297
.Pp
292
Occasionally, when
298
Occasionally, when
293
.Xr timed
299
.Xr timed 8
294
synchronizes the time on many hosts, the setting of a new time value may
300
synchronizes the time on many hosts, the setting of a new time value may
295
require more than a few seconds.
301
require more than a few seconds.
296
On these occasions,
302
On these occasions,
297
.Nm
303
.Nm
298
prints:
304
prints:
299
.Ql Network time being set .
305
.Dq Network time being set .
300
The message
306
The message
301
.Ql Communication error with timed
307
.Dq Communication error with timed
302
occurs when the communication
308
occurs when the communication
303
between
309
between
304
.Nm
310
.Nm
305
and
311
and
306
.Xr timed
312
.Xr timed 8
307
fails.
313
fails.
308
.Sh STANDARDS
314
.Sh STANDARDS
309
The
315
The
310
.Nm
316
.Nm
311
command is expected to be compatible with
317
utility is expected to be compatible with
312
.St -p1003.2 .
318
.St -p1003.2 .
313
.Sh HISTORY
319
.Sh HISTORY
314
A
320
A
(-)date/date.c (-11 / +28 lines)
Lines 50-65 Link Here
50
50
51
#include <ctype.h>
51
#include <ctype.h>
52
#include <err.h>
52
#include <err.h>
53
#include <libutil.h>
54
#include <locale.h>
53
#include <stdio.h>
55
#include <stdio.h>
54
#include <stdlib.h>
56
#include <stdlib.h>
55
#include <string.h>
57
#include <string.h>
56
#include <syslog.h>
58
#include <syslog.h>
57
#include <unistd.h>
59
#include <unistd.h>
58
#include <locale.h>
59
60
60
#include "extern.h"
61
#include "extern.h"
61
#include "vary.h"
62
#include "vary.h"
62
63
64
#ifndef	TM_YEAR_BASE
65
#define	TM_YEAR_BASE	1900
66
#endif
67
63
time_t tval;
68
time_t tval;
64
int retval;
69
int retval;
65
70
Lines 67-74 Link Here
67
static void badformat __P((void));
72
static void badformat __P((void));
68
static void usage __P((void));
73
static void usage __P((void));
69
74
70
int logwtmp __P((char *, char *, char *));
71
72
int
75
int
73
main(argc, argv)
76
main(argc, argv)
74
	int argc;
77
	int argc;
Lines 121-127 Link Here
121
				usage();
124
				usage();
122
			set_timezone = 1;
125
			set_timezone = 1;
123
			break;
126
			break;
124
		case 'u':		/* do everything in GMT */
127
		case 'u':		/* do everything in UTC */
125
			(void)setenv("TZ", "GMT0", 1);
128
			(void)setenv("TZ", "GMT0", 1);
126
			break;
129
			break;
127
		case 'v':
130
		case 'v':
Lines 184-189 Link Here
184
	register struct tm *lt;
187
	register struct tm *lt;
185
	struct timeval tv;
188
	struct timeval tv;
186
	const char *dot, *t;
189
	const char *dot, *t;
190
	int bigyear;
191
	int yearset = 0;
187
192
188
	if (fmt != NULL) {
193
	if (fmt != NULL) {
189
		lt = localtime(&tval);
194
		lt = localtime(&tval);
Lines 221-240 Link Here
221
226
222
		/* if p has a ".ss" field then let's pretend it's not there */
227
		/* if p has a ".ss" field then let's pretend it's not there */
223
		switch (strlen(p) - ((dot != NULL) ? 3 : 0)) {
228
		switch (strlen(p) - ((dot != NULL) ? 3 : 0)) {
229
		case 12:				/* cc */
230
			bigyear = ATOI2(p);
231
			lt->tm_year = bigyear * 100 - TM_YEAR_BASE;
232
			yearset = 1;
233
			/* FALLTHROUGH */
224
		case 10:				/* yy */
234
		case 10:				/* yy */
225
			lt->tm_year = ATOI2(p);
235
			if (yearset) {
226
			if (lt->tm_year < 69)		/* hack for 2000 ;-} */
236
				lt->tm_year += ATOI2(p);
227
				lt->tm_year += 100;
237
			} else {
238
				lt->tm_year = ATOI2(p);
239
				if (lt->tm_year < 69)	/* hack for 2000 ;-} */
240
					lt->tm_year += (2000 - TM_YEAR_BASE);
241
				else
242
					lt->tm_year += (1900 - TM_YEAR_BASE);
243
			}
228
			/* FALLTHROUGH */
244
			/* FALLTHROUGH */
229
		case 8:					/* mm */
245
		case 8:					/* mm */
230
			lt->tm_mon = ATOI2(p);
246
			lt->tm_mon = ATOI2(p);
231
			if (lt->tm_mon > 12)
247
			if ((lt->tm_mon > 12) || !lt->tm_mon)
232
				badformat();
248
				badformat();
233
			--lt->tm_mon;		/* time struct is 0 - 11 */
249
			--lt->tm_mon;		/* time struct is 0 - 11 */
234
			/* FALLTHROUGH */
250
			/* FALLTHROUGH */
235
		case 6:					/* dd */
251
		case 6:					/* dd */
236
			lt->tm_mday = ATOI2(p);
252
			lt->tm_mday = ATOI2(p);
237
			if (lt->tm_mday > 31)
253
			if ((lt->tm_mday > 31) || !lt->tm_mday)
238
				badformat();
254
				badformat();
239
			/* FALLTHROUGH */
255
			/* FALLTHROUGH */
240
		case 4:					/* HH */
256
		case 4:					/* HH */
Lines 254-260 Link Here
254
270
255
	/* convert broken-down time to GMT clock time */
271
	/* convert broken-down time to GMT clock time */
256
	if ((tval = mktime(lt)) == -1)
272
	if ((tval = mktime(lt)) == -1)
257
		errx(1, "nonexistent time");
273
		errx(1, "specified date is outside allowed range");
258
274
259
	if (!jflag) {
275
	if (!jflag) {
260
		/* set the time */
276
		/* set the time */
Lines 286-291 Link Here
286
	(void)fprintf(stderr, "%s\n%s\n",
302
	(void)fprintf(stderr, "%s\n%s\n",
287
	    "usage: date [-nu] [-d dst] [-r seconds] [-t west] "
303
	    "usage: date [-nu] [-d dst] [-r seconds] [-t west] "
288
	    "[-v[+|-]val[ymwdHMS]] ... ",
304
	    "[-v[+|-]val[ymwdHMS]] ... ",
289
	    "            [-f fmt date | [[[[yy]mm]dd]HH]MM[.ss]] [+format]");
305
	    "            [-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] "
306
	    "[+format]");
290
	exit(1);
307
	exit(1);
291
}
308
}

Return to bug 14151