Support seconds with -v.
PR: 6308 Submitted by: Max Euston <meuston@jmrodgers.com>
This commit is contained in:
parent
00d4f4a5f4
commit
269dfbee64
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user