mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2025-01-01 00:18:15 +01:00
Allow the year to be specified with an optional century.
PR: 14472 Reported by: j_guojun@lbl.gov (Jin Guojun)
This commit is contained in:
parent
150c3a33b9
commit
646e0924a1
@ -49,7 +49,7 @@
|
|||||||
.Op Fl t Ar minutes_west
|
.Op Fl t Ar minutes_west
|
||||||
.Op Fl v Ns Ar [+|-]val Ns Op ymwdHMS
|
.Op Fl v Ns Ar [+|-]val Ns Op ymwdHMS
|
||||||
.Ar ...
|
.Ar ...
|
||||||
.Op Fl f Ar fmt Ar date | [[[[yy]mm]dd]HH]MM[\&.ss]
|
.Op Fl f Ar fmt Ar date | [[[[[cc]yy]mm]dd]HH]MM[\&.ss]
|
||||||
.Op Cm + Ns Ar format
|
.Op Cm + Ns Ar format
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm Date
|
.Nm Date
|
||||||
@ -74,7 +74,7 @@ Use
|
|||||||
.Ar fmt
|
.Ar fmt
|
||||||
as the format string to parse the date provided rather than using
|
as the format string to parse the date provided rather than using
|
||||||
the default
|
the default
|
||||||
.Ar [[[[yy]mm]dd]HH]MM[.ss]
|
.Ar [[[[[cc]yy]mm]dd]HH]MM[.ss]
|
||||||
format. Parsing is done using
|
format. Parsing is done using
|
||||||
.Xr strptime 3 .
|
.Xr strptime 3 .
|
||||||
.It Fl j
|
.It Fl j
|
||||||
@ -168,6 +168,8 @@ a value for setting the system's notion of the current date and time.
|
|||||||
The canonical representation for setting the date and time is:
|
The canonical representation for setting the date and time is:
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width Ds -compact -offset indent
|
.Bl -tag -width Ds -compact -offset indent
|
||||||
|
.It Ar cc
|
||||||
|
Century (either 19 or 20) prepended to the abbreviated year.
|
||||||
.It Ar yy
|
.It Ar yy
|
||||||
Year in abbreviated form (e.g. 89 for 1989, 06 for 2006).
|
Year in abbreviated form (e.g. 89 for 1989, 06 for 2006).
|
||||||
.It Ar mm
|
.It Ar mm
|
||||||
|
@ -175,6 +175,8 @@ main(argc, argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
|
#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
|
||||||
|
#define ATOI4(ar) ((ar)[0] - '0') * 1000 + ((ar)[1] - '0') * 100 + \
|
||||||
|
((ar)[2] - '0') * 10 + ((ar)[3] - '0'); (ar) += 4;
|
||||||
void
|
void
|
||||||
setthetime(fmt, p, jflag, nflag)
|
setthetime(fmt, p, jflag, nflag)
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
@ -221,11 +223,16 @@ setthetime(fmt, p, jflag, nflag)
|
|||||||
|
|
||||||
/* if p has a ".ss" field then let's pretend it's not there */
|
/* if p has a ".ss" field then let's pretend it's not there */
|
||||||
switch (strlen(p) - ((dot != NULL) ? 3 : 0)) {
|
switch (strlen(p) - ((dot != NULL) ? 3 : 0)) {
|
||||||
|
case 12: /* cc */
|
||||||
|
lt->tm_year = -1900 + ATOI4(p);
|
||||||
|
if (lt->tm_year < 0)
|
||||||
|
badformat();
|
||||||
|
goto year_done;
|
||||||
case 10: /* yy */
|
case 10: /* yy */
|
||||||
lt->tm_year = ATOI2(p);
|
lt->tm_year = ATOI2(p);
|
||||||
if (lt->tm_year < 69) /* hack for 2000 ;-} */
|
if (lt->tm_year < 69) /* hack for 2000 ;-} */
|
||||||
lt->tm_year += 100;
|
lt->tm_year += 100;
|
||||||
/* FALLTHROUGH */
|
year_done: /* FALLTHROUGH */
|
||||||
case 8: /* mm */
|
case 8: /* mm */
|
||||||
lt->tm_mon = ATOI2(p);
|
lt->tm_mon = ATOI2(p);
|
||||||
if (lt->tm_mon > 12)
|
if (lt->tm_mon > 12)
|
||||||
@ -286,6 +293,7 @@ usage()
|
|||||||
(void)fprintf(stderr, "%s\n%s\n",
|
(void)fprintf(stderr, "%s\n%s\n",
|
||||||
"usage: date [-nu] [-d dst] [-r seconds] [-t west] "
|
"usage: date [-nu] [-d dst] [-r seconds] [-t west] "
|
||||||
"[-v[+|-]val[ymwdHMS]] ... ",
|
"[-v[+|-]val[ymwdHMS]] ... ",
|
||||||
" [-f fmt date | [[[[yy]mm]dd]HH]MM[.ss]] [+format]");
|
" "
|
||||||
|
"[-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user