On Fri, 15 Feb 2019 22:36:08 +0100, Christian Weisgerber wrote:
> The at(1) man page says:
> at allows some moderately complex timespec specifications. It accepts
> times of the form HHMM or HH:MM to run a job at a specific time of day.
> (If that time is already past, the next day is assumed.)
The manual is correct. Below is one way to fix this, though the
logic probably belongs in tod() itself.
- todd
Index: usr.bin/at/parsetime.c
===================================================================
RCS file: /cvs/src/usr.bin/at/parsetime.c,v
retrieving revision 1.26
diff -u -p -u -r1.26 parsetime.c
--- usr.bin/at/parsetime.c 11 Nov 2015 17:42:51 -0000 1.26
+++ usr.bin/at/parsetime.c 15 Feb 2019 22:16:36 -0000
@@ -652,8 +652,22 @@ parsetime(int argc, char **argv)
break;
case NUMBER:
- if (tod(&runtime) != 0 || month(&runtime) != 0)
+ if (tod(&runtime) != 0)
return (-1);
+
+ if (sc_tokid == EOF) {
+ /* If time in form HH:MM is past, assume tomorrow. */
+ if (runtime.tm_mday == nowtime.tm_mday &&
+ runtime.tm_wday == nowtime.tm_wday &&
+ (runtime.tm_hour < nowtime.tm_hour ||
+ (runtime.tm_hour == nowtime.tm_hour &&
+ runtime.tm_min < nowtime.tm_min))) {
+ runtime.tm_mday++;
+ runtime.tm_wday++;
+ }
+ } else if (month(&runtime) != 0) {
+ return (-1);
+ }
break;
/*