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.
|
.\" SUCH DAMAGE.
|
||||||
.\"
|
.\"
|
||||||
.\" @(#)date.1 8.3 (Berkeley) 4/28/95
|
.\" @(#)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
|
.Dd November 17, 1993
|
||||||
.Dt DATE 1
|
.Dt DATE 1
|
||||||
@ -47,7 +47,7 @@
|
|||||||
.Op Fl d Ar dst
|
.Op Fl d Ar dst
|
||||||
.Op Fl r Ar seconds
|
.Op Fl r Ar seconds
|
||||||
.Op Fl t Ar minutes_west
|
.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 ...
|
.Ar ...
|
||||||
.Op Fl f Ar fmt Ar date | [[[[yy]mm]dd]HH]MM[\&.ss]
|
.Op Fl f Ar fmt Ar date | [[[[yy]mm]dd]HH]MM[\&.ss]
|
||||||
.Op Cm + Ns Ar format
|
.Op Cm + Ns Ar format
|
||||||
@ -108,8 +108,8 @@ Display or set the date in
|
|||||||
.Tn UCT
|
.Tn UCT
|
||||||
(universal) time.
|
(universal) time.
|
||||||
.It Fl v
|
.It Fl v
|
||||||
Adjust the minute, hour, month day, week day, month or year according to
|
Adjust the second, minute, hour, month day, week day, month or year according to
|
||||||
.Ar val .
|
.Ar val .
|
||||||
If
|
If
|
||||||
.Ar val
|
.Ar val
|
||||||
is preceded with a plus or minus sign, the date is adjusted forwards
|
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
|
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.
|
required using these flags. Flags are processed in the order given.
|
||||||
.Pp
|
.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
|
||||||
are in the range 1-31, week days are in the range 0-6 (Sun-Sat), months
|
in the range 1-12, month days are in the range 1-31, week days are in the
|
||||||
are in the range 1-12 (Jan-Dec) and years are in the range 80-38 or
|
range 0-6 (Sun-Sat), months are in the range 1-12 (Jan-Dec) and years are
|
||||||
1980-2038.
|
in the range 80-38 or 1980-2038.
|
||||||
.Pp
|
.Pp
|
||||||
If
|
If
|
||||||
.Ar val
|
.Ar val
|
||||||
@ -129,9 +129,10 @@ is numeric, one of either
|
|||||||
.Ar m ,
|
.Ar m ,
|
||||||
.Ar w ,
|
.Ar w ,
|
||||||
.Ar d ,
|
.Ar d ,
|
||||||
.Ar H
|
.Ar H ,
|
||||||
or
|
|
||||||
.Ar M
|
.Ar M
|
||||||
|
or
|
||||||
|
.Ar S
|
||||||
must be used to specify which part of the date is to be adjusted.
|
must be used to specify which part of the date is to be adjusted.
|
||||||
.Pp
|
.Pp
|
||||||
The week day or month may be specified using a name rather than a
|
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";
|
static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
|
||||||
#endif
|
#endif
|
||||||
static const char rcsid[] =
|
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 */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
@ -278,7 +278,7 @@ usage()
|
|||||||
{
|
{
|
||||||
(void)fprintf(stderr, "%s\n%s\n",
|
(void)fprintf(stderr, "%s\n%s\n",
|
||||||
"usage: date [-nu] [-d dst] [-r seconds] [-t west] "
|
"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]");
|
" [-f fmt date | [[[[yy]mm]dd]HH]MM[.ss]] [+format]");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static const char rcsid[] =
|
static const char rcsid[] =
|
||||||
"$Id$";
|
"$Id: vary.c,v 1.4 1998/05/06 06:51:20 charnier Exp $";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -332,6 +332,43 @@ adjmin(struct tm *t, char type, int val)
|
|||||||
return mktime(t) != -1;
|
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 *
|
const struct vary *
|
||||||
vary_apply(const struct vary *v, struct tm *t)
|
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];
|
which = arg[len-1];
|
||||||
|
|
||||||
switch (which) {
|
switch (which) {
|
||||||
|
case 'S':
|
||||||
|
if (!adjsec(t, type, val))
|
||||||
|
return v;
|
||||||
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
if (!adjmin(t, type, val))
|
if (!adjmin(t, type, val))
|
||||||
return v;
|
return v;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user