diff options
author | Sheldon Hearn <sheldonh@FreeBSD.org> | 1999-11-10 13:34:39 +0000 |
---|---|---|
committer | Sheldon Hearn <sheldonh@FreeBSD.org> | 1999-11-10 13:34:39 +0000 |
commit | 646e0924a1292fa46464e08990d513e8d76db7db (patch) | |
tree | 526f3e2ab3a46ba3964b3af20e0fac3412a7c9f4 /bin/date/date.c | |
parent | 150c3a33b9d9b08a93cfaa03df03aa944a1b091a (diff) | |
download | src-646e0924a1292fa46464e08990d513e8d76db7db.tar.gz src-646e0924a1292fa46464e08990d513e8d76db7db.zip |
Allow the year to be specified with an optional century.
PR: 14472
Reported by: j_guojun@lbl.gov (Jin Guojun)
Notes
Notes:
svn path=/head/; revision=53082
Diffstat (limited to 'bin/date/date.c')
-rw-r--r-- | bin/date/date.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/bin/date/date.c b/bin/date/date.c index d699755c7d0f..4d4c9cde1a33 100644 --- a/bin/date/date.c +++ b/bin/date/date.c @@ -175,6 +175,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, jflag, nflag) 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 */ 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) @@ -286,6 +293,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); } |