From nsmart@indigo.ie  Wed Apr 15 12:45:05 1998
Received: from indigo.ie (root@ts01-49.waterford.indigo.ie [194.125.139.112])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id MAA16657
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 15 Apr 1998 12:45:01 GMT
          (envelope-from nsmart@indigo.ie)
Received: (from nsmart@localhost)
	by indigo.ie (8.8.8/8.8.7) id AAA00922;
	Fri, 1 Jan 2038 00:00:40 GMT
	(envelope-from nsmart)
Message-Id: <203801010000.AAA00922@indigo.ie>
Date: Fri, 1 Jan 2038 00:00:40 GMT
From: rotel@indigo.ie
Reply-To: nsmart@indigo.ie
To: FreeBSD-gnats-submit@freebsd.org
Subject: date(1) -v argument cannot vary seconds
X-Send-Pr-Version: 3.2

>Number:         6308
>Category:       bin
>Synopsis:       [PATCH] date(1) -v argument cannot vary seconds
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 15 05:50:01 PDT 1998
>Closed-Date:    Tue Mar 9 01:39:06 PST 1999
>Last-Modified:  Tue Mar  9 01:39:25 PST 1999
>Originator:     Niall Smart
>Release:        FreeBSD 2.2.6-STABLE i386
>Organization:
>Environment:

>Description:

The -v option to date(1) allows the user to vary the year, month,
day, hour and minute of the current date, but not the seconds.
This is definately not a show stopper :) but should be done for
consistency IMHO.

>How-To-Repeat:

>Fix:

No patch supplied.
>Release-Note:
>Audit-Trail:

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>
 
 
State-Changed-From-To: open->suspended 
State-Changed-By: phk 
State-Changed-When: Tue May 19 23:04:54 PDT 1998 
State-Changed-Why:  
awaiting committer 
State-Changed-From-To: suspended->closed 
State-Changed-By: brian 
State-Changed-When: Tue Mar 9 01:39:06 PST 1999 
State-Changed-Why:  
Patches applied to -current. 
>Unformatted:
