summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1999-03-09 09:38:54 +0000
committerbrian <brian@FreeBSD.org>1999-03-09 09:38:54 +0000
commitf5ccad82da71fe40b484de65100b0d380f101bee (patch)
treef5b7413731c0d902bdbfefd4a681903bb0e12f8a /bin
parent143686d0c8e3ceb676f18e37b90d20973d4f0649 (diff)
downloadFreeBSD-src-f5ccad82da71fe40b484de65100b0d380f101bee.zip
FreeBSD-src-f5ccad82da71fe40b484de65100b0d380f101bee.tar.gz
Support seconds with -v.
PR: 6308 Submitted by: Max Euston <meuston@jmrodgers.com>
Diffstat (limited to 'bin')
-rw-r--r--bin/date/date.121
-rw-r--r--bin/date/date.c4
-rw-r--r--bin/date/vary.c43
3 files changed, 55 insertions, 13 deletions
diff --git a/bin/date/date.1 b/bin/date/date.1
index cf0c792..11a59d6 100644
--- a/bin/date/date.1
+++ b/bin/date/date.1
@@ -33,7 +33,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
-.\" $Id: date.1,v 1.25 1998/05/13 07:56:44 phk Exp $
+.\" $Id: date.1,v 1.26 1999/01/13 07:01:07 danny Exp $
.\"
.Dd November 17, 1993
.Dt DATE 1
@@ -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 @@ Display or set the date in
.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 preceded with a plus or minus sign, the date is adjusted forwards
@@ -117,10 +117,10 @@ or backwards according to the remaining string, otherwise the relevant
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
-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.
+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.
.Pp
If
.Ar val
@@ -129,9 +129,10 @@ is numeric, one of either
.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 --git a/bin/date/date.c b/bin/date/date.c
index 043cdcc..e116e3d 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -42,7 +42,7 @@ static char const copyright[] =
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
#endif
static const char rcsid[] =
- "$Id: date.c,v 1.25 1998/05/13 07:31:39 charnier Exp $";
+ "$Id: date.c,v 1.26 1998/10/03 16:29:59 alex Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -278,7 +278,7 @@ usage()
{
(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 --git a/bin/date/vary.c b/bin/date/vary.c
index a6419d5..d2345d4 100644
--- a/bin/date/vary.c
+++ b/bin/date/vary.c
@@ -26,7 +26,7 @@
#ifndef lint
static const char rcsid[] =
- "$Id$";
+ "$Id: vary.c,v 1.4 1998/05/06 06:51:20 charnier Exp $";
#endif /* not lint */
#include <time.h>
@@ -332,6 +332,43 @@ adjmin(struct tm *t, char type, int val)
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)
{
@@ -370,6 +407,10 @@ vary_apply(const struct vary *v, struct tm *t)
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;
OpenPOWER on IntegriCloud