summaryrefslogtreecommitdiffstats
path: root/bin/date/vary.c
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/date/vary.c
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/date/vary.c')
-rw-r--r--bin/date/vary.c43
1 files changed, 42 insertions, 1 deletions
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