]> gitweb.factorcode.org Git - factor.git/commitdiff
crontab: simplify (next-time-after) recursion.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sat, 23 Mar 2019 03:57:50 +0000 (20:57 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sat, 23 Mar 2019 03:57:50 +0000 (20:57 -0700)
extra/crontab/crontab.factor

index 1f5b8e0f6a2af7a6cab04ccfe419a43c1d587654..2289c7ec265d1bd9adf2968c3a099a85dd3eb4de 100644 (file)
@@ -57,41 +57,44 @@ CONSTANT: aliases H{
 
 :: (next-time-after) ( cronentry timestamp -- )
 
+    f ! should we keep searching for a matching time
+
     timestamp month>> :> month
     cronentry months>> [ month >= ] find nip
-    dup month = [ drop ] [
+    dup month = [ drop ] [
         [ cronentry months>> first timestamp 1 +year drop ] unless*
-        timestamp 1 >>day 0 >>hour 0 >>minute month<< t
-    ] if [ cronentry timestamp (next-time-after) ] when
+        timestamp 1 >>day 0 >>hour 0 >>minute month<< drop t
+    ] if
 
     timestamp day>> :> day
     cronentry days>> [ day >= ] find nip
-    dup day = [ drop ] [
+    dup day = [ drop ] [
         [ cronentry days>> first timestamp 1 +month drop ] unless*
-        timestamp 0 >>hour 0 >>minute day<< t
-    ] if [ cronentry timestamp (next-time-after) ] when
+        timestamp 0 >>hour 0 >>minute day<< drop t
+    ] if
 
     timestamp day-of-week :> weekday
     cronentry days-of-week>> [ weekday >= ] find nip [
         cronentry days-of-week>> first 7 +
     ] unless* weekday - [
-        timestamp 0 >>hour 0 >>minute swap +day drop
-        cronentry timestamp (next-time-after)
+        timestamp 0 >>hour 0 >>minute swap +day 2drop t
     ] unless-zero
 
     timestamp hour>> :> hour
     cronentry hours>> [ hour >= ] find nip
-    dup hour = [ drop ] [
+    dup hour = [ drop ] [
         [ cronentry hours>> first timestamp 1 +day drop ] unless*
-        timestamp 0 >>minute hour<< t
-    ] if [ cronentry timestamp (next-time-after) ] when
+        timestamp 0 >>minute hour<< drop t
+    ] if
 
     timestamp minute>> :> minute
     cronentry minutes>> [ minute >= ] find nip
-    dup minute = [ drop ] [
+    dup minute = [ drop ] [
         [ cronentry minutes>> first timestamp 1 +hour drop ] unless*
-        timestamp minute<< t
-    ] if [ cronentry timestamp (next-time-after) ] when ;
+        timestamp minute<< drop t
+    ] if
+
+    [ cronentry timestamp (next-time-after) ] when ;
 
 PRIVATE>