]> gitweb.factorcode.org Git - factor.git/commitdiff
crontab: avoid next-time being minutes in the past.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 17 Mar 2019 15:55:36 +0000 (08:55 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 17 Mar 2019 15:55:36 +0000 (08:55 -0700)
extra/crontab/crontab-tests.factor
extra/crontab/crontab.factor

index e0ba8d6deaa6c2fdd235f60ee5d4d98945ab2ed9..5701b8b1452802c25b22d622448ff52449fe7d2b 100644 (file)
@@ -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
index f9c010b22ee7d5a047e3ce9cfa6c77e2bee4b44d..50c9e069516834f7e4279c8ee3c79ef4bc90a8b4 100644 (file)
@@ -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 ;