Allow a century to be specified.
Cut and paste some text from touch(1) about date parsing.
This commit is contained in:
parent
a5f873989a
commit
f9a6471ec7
@ -1,4 +1,4 @@
|
||||
.\" $NetBSD: date.1,v 1.18 1997/11/03 18:42:49 kleink Exp $
|
||||
.\" $NetBSD: date.1,v 1.19 1998/01/20 21:16:38 mycroft Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1990, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
@ -36,7 +36,7 @@
|
||||
.\"
|
||||
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
|
||||
.\"
|
||||
.Dd April 28, 1995
|
||||
.Dd January 20, 1998
|
||||
.Dt DATE 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -47,7 +47,7 @@
|
||||
.Op Fl r Ar seconds
|
||||
.Op Fl nu
|
||||
.Op Cm + Ns Ar format
|
||||
.Op [yy[mm[dd[hh]]]]mm[\&.ss]
|
||||
.Op [[cc]yy[mm[dd[hh]]]]mm[\&.ss]
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
displays the current date and time when invoked without arguments.
|
||||
@ -99,20 +99,30 @@ a value for setting the system's notion of the current date and time.
|
||||
The canonical representation for setting the date and time is:
|
||||
.Pp
|
||||
.Bl -tag -width Ds -compact -offset indent
|
||||
.It Ar cc
|
||||
The first two digits of the year (the century).
|
||||
.It Ar yy
|
||||
Year in abbreviated form (e.g. 89 for 1989. Years 00
|
||||
to 68 are interpreted as being after the year 2000.)
|
||||
The second two digits of the year. If
|
||||
.Dq yy
|
||||
is specified, but
|
||||
.Dq cc
|
||||
is not, a value for
|
||||
.Dq yy
|
||||
between 69 and 99 results in a
|
||||
.Dq cc
|
||||
value of 19. Otherwise, a
|
||||
.Dq cc
|
||||
value of 20 is used.
|
||||
.It Ar mm
|
||||
Numeric month.
|
||||
A number from 1 to 12.
|
||||
The month of the year, from 1 to 12.
|
||||
.It Ar dd
|
||||
Day, a number from 1 to 31.
|
||||
The day of the month, from 1 to 31.
|
||||
.It Ar hh
|
||||
Hour, a number from 0 to 23.
|
||||
The hour of the day, from 0 to 23.
|
||||
.It Ar mm
|
||||
Minutes, a number from 0 to 59.
|
||||
.It Ar .ss
|
||||
Seconds, a number from 0 to 61 (59 plus a maximum of two leap seconds).
|
||||
The minute of the hour, from 0 to 59.
|
||||
.It Ar ss
|
||||
The second of the minute, from 0 to 61.
|
||||
.El
|
||||
.Pp
|
||||
Everything but the minutes is optional.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: date.c,v 1.17 1998/01/20 20:54:56 mycroft Exp $ */
|
||||
/* $NetBSD: date.c,v 1.18 1998/01/20 21:16:39 mycroft Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1985, 1987, 1988, 1993
|
||||
@ -44,7 +44,7 @@ __COPYRIGHT(
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: date.c,v 1.17 1998/01/20 20:54:56 mycroft Exp $");
|
||||
__RCSID("$NetBSD: date.c,v 1.18 1998/01/20 21:16:39 mycroft Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -59,6 +59,7 @@ __RCSID("$NetBSD: date.c,v 1.17 1998/01/20 20:54:56 mycroft Exp $");
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
#include <syslog.h>
|
||||
#include <tzfile.h>
|
||||
#include <unistd.h>
|
||||
#include <util.h>
|
||||
|
||||
@ -136,6 +137,7 @@ setthetime(p)
|
||||
struct tm *lt;
|
||||
struct timeval tv;
|
||||
char *dot, *t;
|
||||
int yearset;
|
||||
|
||||
for (t = p, dot = NULL; *t; ++t) {
|
||||
if (isdigit(*t))
|
||||
@ -159,13 +161,25 @@ setthetime(p)
|
||||
} else
|
||||
lt->tm_sec = 0;
|
||||
|
||||
yearset = 0;
|
||||
switch (strlen(p)) {
|
||||
case 10: /* yy */
|
||||
case 12:
|
||||
lt->tm_year = ATOI2(p);
|
||||
if (lt->tm_year < 69) /* hack for 2000 ;-} */
|
||||
lt->tm_year += 2000 - TM_YEAR_BASE;
|
||||
else
|
||||
lt->tm_year += 1900 - TM_YEAR_BASE;
|
||||
lt->tm_year *= 100;
|
||||
yearset = 1;
|
||||
/* FALLTHROUGH */
|
||||
case 10: /* yy */
|
||||
if (yearset) {
|
||||
yearset = ATOI2(p);
|
||||
lt->tm_year += yearset;
|
||||
} else {
|
||||
yearset = ATOI2(p);
|
||||
if (yearset < 69) /* hack for 2000 ;-} */
|
||||
lt->tm_year = yearset + 2000;
|
||||
else
|
||||
lt->tm_year = yearset + 1900;
|
||||
}
|
||||
lt->tm_year -= TM_YEAR_BASE;
|
||||
/* FALLTHROUGH */
|
||||
case 8: /* mm */
|
||||
lt->tm_mon = ATOI2(p);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: netdate.c,v 1.13 1998/01/10 00:27:34 lukem Exp $ */
|
||||
/* $NetBSD: netdate.c,v 1.14 1998/01/20 21:16:40 mycroft Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
@ -38,7 +38,7 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)netdate.c 8.2 (Berkeley) 4/28/95";
|
||||
#else
|
||||
__RCSID("$NetBSD: netdate.c,v 1.13 1998/01/10 00:27:34 lukem Exp $");
|
||||
__RCSID("$NetBSD: netdate.c,v 1.14 1998/01/20 21:16:40 mycroft Exp $");
|
||||
#endif
|
||||
#endif /* not lint */
|
||||
|
||||
@ -81,7 +81,10 @@ netsettime(tval)
|
||||
struct sockaddr_in sin, dest, from;
|
||||
fd_set ready;
|
||||
long waittime;
|
||||
int s, length, on, timed_ack, found, err;
|
||||
int s, length, timed_ack, found, err;
|
||||
#ifdef IP_PORTRANGE
|
||||
int on;
|
||||
#endif
|
||||
char hostname[MAXHOSTNAMELEN];
|
||||
|
||||
if ((sp = getservbyname("timed", "udp")) == NULL) {
|
||||
@ -101,11 +104,13 @@ netsettime(tval)
|
||||
return (retval = 2);
|
||||
}
|
||||
|
||||
#ifdef IP_PORTRANGE
|
||||
on = IP_PORTRANGE_LOW;
|
||||
if (setsockopt(s, IPPROTO_IP, IP_PORTRANGE, &on, sizeof(on)) < 0) {
|
||||
warn("setsockopt");
|
||||
goto bad;
|
||||
}
|
||||
#endif
|
||||
|
||||
(void)memset(&sin, 0, sizeof(sin));
|
||||
sin.sin_len = sizeof(struct sockaddr_in);
|
||||
|
Loading…
Reference in New Issue
Block a user