Date: Wed, 15 Apr 1998 13:10:12 -0700 (PDT) From: Max Euston <meuston@jmrodgers.com> To: freebsd-bugs Subject: RE: bin/6308: date(1) -v argument cannot vary seconds Message-ID: <199804152010.NAA27889@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/6308; it has been noted by GNATS.
From: Max Euston <meuston@jmrodgers.com>
To: "'nsmart@indigo.ie'" <nsmart@indigo.ie>,
"FreeBSD-gnats-submit@FreeBSD.ORG" <FreeBSD-gnats-submit@FreeBSD.ORG>
Cc: Subject: RE: bin/6308: date(1) -v argument cannot vary seconds
Date: Wed, 15 Apr 1998 16:05:48 -0400
Boy, I must be bored or something... 8-)
diff -u /usr/src/bin/date/date.1 ./date.1
--- /usr/src/bin/date/date.1 Fri Feb 20 15:32:31 1998
+++ ./date.1 Wed Apr 15 14:41:01 1998
@@ -47,7 +47,7 @@
.Op Fl d Ar dst
.Op Fl r Ar seconds
.Op Fl t Ar minutes_west
-.Op Fl v Ns Ar [+|-]val Ns Op ymwdHM
+.Op Fl v Ns Ar [+|-]val Ns Op ymwdHMS
.Ar ...
.Op Fl f Ar fmt Ar date | [[[[yy]mm]dd]HH]MM[\&.ss]
.Op Cm + Ns Ar format
@@ -108,8 +108,8 @@
.Tn UCT
(universal) time.
.It Fl v
-Adjust the minute, hour, month day, week day, month or year according to
-.Ar val .
+Adjust the second, minute, hour, month day, week day, month or year according to
+.Ar val .
If
.Ar val
is preceeded with a plus or minus sign, the date is adjusted forwards
@@ -117,7 +117,8 @@
part of the date is set. The date can be adjusted as many times as
required using these flags. Flags are processed in the order given.
.Pp
-Minutes are in the range 0-59, hours are in the range 1-12, month days
+Seconds are in the range 0-59,
+minutes are in the range 0-59, hours are in the range 1-12, month days
are in the range 1-31, week days are in the range 0-6 (sun-sat), months
are in the range 1-12 (jan-dec) and years are in the range 80-38 or
1980-2038.
@@ -129,9 +130,10 @@
.Ar m ,
.Ar w ,
.Ar d ,
-.Ar H
-or
+.Ar H ,
.Ar M
+or
+.Ar S
must be used to specify which part of the date is to be adjusted.
.Pp
The week day or month may be specified using a name rather than a
diff -u /usr/src/bin/date/date.c ./date.c
--- /usr/src/bin/date/date.c Fri Feb 20 15:32:31 1998
+++ ./date.c Wed Apr 15 14:45:04 1998
@@ -277,7 +277,7 @@
{
(void)fprintf(stderr, "%s\n%s\n",
"usage: date [-nu] [-d dst] [-r seconds] [-t west] "
- "[-v[+|-]val[ymwdHM]] ... ",
+ "[-v[+|-]val[ymwdHMS]] ... ",
" [-f fmt date | [[[[yy]mm]dd]HH]MM[.ss]] [+format]");
exit(1);
}
diff -u /usr/src/bin/date/vary.c ./vary.c
--- /usr/src/bin/date/vary.c Fri Feb 20 15:32:32 1998
+++ ./vary.c Wed Apr 15 14:25:16 1998
@@ -329,6 +329,43 @@
return mktime(t) != -1;
}
+static int
+adjsec(struct tm *t, char type, int val)
+{
+ if (val < 0)
+ return 0;
+
+ switch (type) {
+ case '+':
+ if (!adjmin(t, '+', (t->tm_sec + val) / 60))
+ return 0;
+ val %= 60;
+ t->tm_sec += val;
+ if (t->tm_sec > 59)
+ t->tm_sec -= 60;
+ break;
+
+ case '-':
+ if (!adjmin(t, '-', val / 60))
+ return 0;
+ val %= 60;
+ if (val > t->tm_sec) {
+ if (!adjmin(t, '-', 1))
+ return 0;
+ val -= 60;
+ }
+ t->tm_sec -= val;
+ break;
+
+ default:
+ if (val > 59)
+ return 0;
+ t->tm_sec = val;
+ }
+
+ return mktime(t) != -1;
+}
+
const struct vary *
vary_apply(const struct vary *v, struct tm *t)
{
@@ -367,6 +404,10 @@
which = arg[len-1];
switch (which) {
+ case 'S':
+ if (!adjsec(t, type, val))
+ return v;
+ break;
case 'M':
if (!adjmin(t, type, val))
return v;
Max
-----
Max Euston <meuston@jmrodgers.com>
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199804152010.NAA27889>
