]> gitweb.factorcode.org Git - factor.git/commitdiff
crontab: fix 2/26 * * * *
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 5 Apr 2023 22:23:49 +0000 (15:23 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 5 Apr 2023 22:23:49 +0000 (15:23 -0700)
extra/crontab/crontab-tests.factor
extra/crontab/crontab.factor

index 4f03eab421e58aae31fea15ea3be904e7a6b3ca1..8a0604e26e9c590036e26cf475c090ff18f40fdc 100644 (file)
@@ -143,3 +143,25 @@ CONSTANT: start-timestamp T{ timestamp
         "Fri, 29 Feb 2036 00:00:00 -0700"
     }
 } [ "0 0 29 2 *" next-few-times ] unit-test
+
+! At every 26th minute from 2 through 59 past hour 4.
+{
+    {
+        "Sun, 24 Mar 2019 04:02:00 -0700"
+        "Sun, 24 Mar 2019 04:28:00 -0700"
+        "Sun, 24 Mar 2019 04:54:00 -0700"
+        "Mon, 25 Mar 2019 04:02:00 -0700"
+        "Mon, 25 Mar 2019 04:28:00 -0700"
+    }
+} [ "2/26 4 * * *" next-few-times ] unit-test
+
+! At every 3rd minute from 5 through 20 past hour 4.
+{
+    {
+        "Sun, 24 Mar 2019 04:05:00 -0700"
+        "Sun, 24 Mar 2019 04:08:00 -0700"
+        "Sun, 24 Mar 2019 04:11:00 -0700"
+        "Sun, 24 Mar 2019 04:14:00 -0700"
+        "Sun, 24 Mar 2019 04:17:00 -0700"
+    }
+} [ "5-20/3 4 * * *" next-few-times ] unit-test
index 83fedc0f832417ea3b5e13d1d1c899b2dbe3eaf3..b1940c6815c6853794d81c7487122340c6a84f32 100644 (file)
@@ -15,8 +15,11 @@ ERROR: invalid-cronentry value ;
             "," split [ quot seq parse-value ] map concat ] }
         { [ dup "*" = ] [ drop seq ] }
         { [ CHAR: / over member? ] [
-            "/" split1 [ quot seq parse-value 0 over length 1 - ] dip
-            string>number <range> swap nths ] }
+            "/" split1 [
+                quot seq parse-value
+                dup length 1 = [ seq swap first ] [ 0 ] if
+                over length 1 -
+            ] dip string>number <range> swap nths ] }
         { [ CHAR: - over member? ] [
             "-" split1 quot bi@ [a..b] ] }
         [ quot call 1array ]