From 112263ca3cc5700c26f91d1f29abb662ce759cdd Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 17 Mar 2019 08:55:36 -0700 Subject: [PATCH] crontab: avoid next-time being minutes in the past. --- extra/crontab/crontab-tests.factor | 6 +++++- extra/crontab/crontab.factor | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/extra/crontab/crontab-tests.factor b/extra/crontab/crontab-tests.factor index e0ba8d6dea..5701b8b145 100644 --- a/extra/crontab/crontab-tests.factor +++ b/extra/crontab/crontab-tests.factor @@ -1,4 +1,4 @@ -USING: calendar crontab kernel tools.test ; +USING: calendar crontab kernel math.order tools.test ; { T{ timestamp @@ -20,3 +20,7 @@ USING: calendar crontab kernel tools.test ; { gmt-offset T{ duration { hour -8 } } } } [ next-time-after ] keep ] unit-test + +{ +lt+ } [ + now "*/1 * * * *" parse-cronentry next-time <=> +] unit-test diff --git a/extra/crontab/crontab.factor b/extra/crontab/crontab.factor index f9c010b22e..50c9e06951 100644 --- a/extra/crontab/crontab.factor +++ b/extra/crontab/crontab.factor @@ -55,6 +55,10 @@ CONSTANT: aliases H{ :: next-time-after ( cronentry timestamp -- ) + timestamp second>> 0 > [ + timestamp 0 >>second 1 minutes (time+) 2drop + ] when + timestamp month>> :> month cronentry months>> [ month >= ] find nip [ dup month = [ drop f ] [ timestamp month<< t ] if @@ -98,7 +102,7 @@ CONSTANT: aliases H{ ] unless-zero ; : next-time ( cronentry -- timestamp ) - now 0 >>second [ next-time-after ] keep ; + now [ next-time-after ] keep ; : parse-crontab ( -- entries ) lines harvest [ parse-cronentry ] map ;