diff options
| author | Sheldon Hearn <sheldonh@FreeBSD.org> | 1999-12-15 13:57:04 +0000 |
|---|---|---|
| committer | Sheldon Hearn <sheldonh@FreeBSD.org> | 1999-12-15 13:57:04 +0000 |
| commit | 274fc46902e93cf13ccd79da100b1648e124e37b (patch) | |
| tree | 5f0f61e61b8858a170244dd317b07802dbb14a52 | |
| parent | 089945d6d01f1d018995c34f1debd05aef124d28 (diff) | |
Notes
| -rw-r--r-- | bin/date/date.1 | 6 | ||||
| -rw-r--r-- | bin/date/date.c | 12 |
2 files changed, 14 insertions, 4 deletions
diff --git a/bin/date/date.1 b/bin/date/date.1 index fae00f3a0bcc..1366b6ed40fd 100644 --- a/bin/date/date.1 +++ b/bin/date/date.1 @@ -49,7 +49,7 @@ .Op Fl t Ar minutes_west .Op Fl v Ns Ar [+|-]val Ns Op ymwdHMS .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 .Sh DESCRIPTION .Nm Date @@ -74,7 +74,7 @@ Use .Ar fmt as the format string to parse the date provided rather than using the default -.Ar [[[[yy]mm]dd]HH]MM[.ss] +.Ar [[[[[cc]yy]mm]dd]HH]MM[.ss] format. Parsing is done using .Xr strptime 3 . .It Fl n @@ -162,6 +162,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: .Pp .Bl -tag -width Ds -compact -offset indent +.It Ar cc +Century (either 19 or 20) prepended to the abbreviated year. .It Ar yy Year in abbreviated form (e.g. 89 for 1989, 06 for 2006). .It Ar mm diff --git a/bin/date/date.c b/bin/date/date.c index a8975e10e3f8..779ab2f3189f 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -170,6 +170,8 @@ main(argc, argv) } #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 setthetime(fmt, p) const char *fmt; @@ -215,11 +217,16 @@ setthetime(fmt, p) /* if p has a ".ss" field then let's pretend it's not there */ 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 */ lt->tm_year = ATOI2(p); if (lt->tm_year < 69) /* hack for 2000 ;-} */ lt->tm_year += 100; - /* FALLTHROUGH */ +year_done: /* FALLTHROUGH */ case 8: /* mm */ lt->tm_mon = ATOI2(p); if (lt->tm_mon > 12) @@ -278,6 +285,7 @@ usage() (void)fprintf(stderr, "%s\n%s\n", "usage: date [-nu] [-d dst] [-r seconds] [-t west] " "[-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); } |
