summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2000-05-08 16:15:30 +0000
committerMarc Espie <espie@cvs.openbsd.org>2000-05-08 16:15:30 +0000
commita1545a076dab9eff41c8a99089b3d36d8cce71d7 (patch)
tree1cdc7ddd3272d98ebcf7a0326433213785245010
parent7d48286dcf6527850384e61dfce493e16908871f (diff)
Fix 12 hours handling, so that you can say leave 1830 when it is 1800.
(Anything over 1300 is obviously 24 hours based, and interval arithmetic is much simpler than the old code would make you believe...)
-rw-r--r--usr.bin/leave/leave.16
-rw-r--r--usr.bin/leave/leave.c18
2 files changed, 14 insertions, 10 deletions
diff --git a/usr.bin/leave/leave.1 b/usr.bin/leave/leave.1
index d07721e07f5..f2cd8192313 100644
--- a/usr.bin/leave/leave.1
+++ b/usr.bin/leave/leave.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: leave.1,v 1.7 2000/03/23 21:39:54 aaron Exp $
+.\" $OpenBSD: leave.1,v 1.8 2000/05/08 16:15:29 espie Exp $
.\" $NetBSD: leave.1,v 1.5 1995/08/31 22:32:10 jtc Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
@@ -70,8 +70,8 @@ is a time in
hours (on a 12 or 24 hour clock), and
.Ar mm
in minutes.
-All times are converted to a 12 hour clock, and assumed to
-be in the next 12 hours.
+In ambiguous cases, times are converted to a 12 hour clock,
+and assumed to be in the next 12 hours.
.It Cm \&+
If the time is preceded by
.Ql + ,
diff --git a/usr.bin/leave/leave.c b/usr.bin/leave/leave.c
index d53f5e07731..324f4aa7414 100644
--- a/usr.bin/leave/leave.c
+++ b/usr.bin/leave/leave.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: leave.c,v 1.3 1997/09/08 09:34:44 deraadt Exp $ */
+/* $OpenBSD: leave.c,v 1.4 2000/05/08 16:15:29 espie Exp $ */
/* $NetBSD: leave.c,v 1.4 1995/07/03 16:50:13 phil Exp $ */
/*
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: leave.c,v 1.3 1997/09/08 09:34:44 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: leave.c,v 1.4 2000/05/08 16:15:29 espie Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -110,11 +110,15 @@ main(argc, argv)
else {
if (hours > 23)
usage();
- if (t->tm_hour >= 12)
- t->tm_hour -= 12;
- if (t->tm_hour > hours ||
- (t->tm_hour == hours && minutes <= t->tm_min))
- hours += 12;
+ if (t->tm_hour > hours ||
+ (t->tm_hour == hours && t->tm_min >= minutes)) {
+ /* determine 24 hours mode */
+ if (hours >= 13)
+ hours += 24;
+ else
+ hours += 12;
+ }
+
secs = (hours - t->tm_hour) * 60 * 60;
secs += (minutes - t->tm_min) * 60;
}