]> gitweb.factorcode.org Git - factor.git/commitdiff
crontab: fixing another case
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 6 Apr 2023 16:58:13 +0000 (09:58 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 6 Apr 2023 16:58:13 +0000 (09:58 -0700)
extra/crontab/crontab-tests.factor
extra/crontab/crontab.factor

index 51dcb92fa026dbb787b8c28d16903671701f1610..6874249741dff1a3868cccb40124ef9ac5fecfe2 100644 (file)
@@ -187,3 +187,14 @@ CONSTANT: start-timestamp T{ timestamp
         "Mon, 1 Apr 2019 04:05:00 -0700"
     }
 } [ "5 4 * * 1/3" next-few-times ] unit-test
+
+! At 04:05 on every 2nd day-of-month from 1 through 5.
+{
+    {
+        "Mon, 1 Apr 2019 04:05:00 -0700"
+        "Wed, 3 Apr 2019 04:05:00 -0700"
+        "Fri, 5 Apr 2019 04:05:00 -0700"
+        "Wed, 1 May 2019 04:05:00 -0700"
+        "Fri, 3 May 2019 04:05:00 -0700"
+    }
+} [ "5 4 1-5/2 * *" next-few-times ] unit-test
index d1eb4cde75c8a1e03df381bedcf6404afe8f8c8d..5e6da92718389d0475dd650fdb6dd2c5e127b6c9 100644 (file)
@@ -18,13 +18,13 @@ ERROR: invalid-cronentry value ;
         { [ CHAR: / over member? ] [
             "/" split1 [
                 quot seq parse-value
-                dup length 1 = [ seq swap first ] [ 0 ] if
+                dup length 1 = [ seq swap first seq first - ] [ 0 ] if
                 over length dup 7 = [ [ <circular> ] 2dip ] [ 1 - ] if
             ] dip string>number <range> swap nths ] }
         { [ CHAR: - over member? ] [
             "-" split1 quot bi@ [a..b] ] }
         [ quot call 1array ]
-    } cond ; inline recursive
+    } cond members sort ; inline recursive
 
 : parse-day ( str -- n )
     [ string>number dup 7 = [ drop 0 ] when ] [
@@ -68,7 +68,7 @@ CONSTANT: aliases H{
         [ [ string>number ] T{ range f 0 24 1 } parse-value ]
         [ [ string>number ] T{ range f 1 31 1 } parse-value ]
         [ [ parse-month ] T{ range f 1 12 1 } parse-value ]
-        [ [ parse-day ] T{ range f 0 7 1 } parse-value members sort ]
+        [ [ parse-day ] T{ range f 0 7 1 } parse-value ]
         [ ]
     } spread cronentry boa check-cronentry ;