]> gitweb.factorcode.org Git - factor.git/commitdiff
crontab: handle more non-standard day-of-week fractions
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 6 Apr 2023 15:48:34 +0000 (08:48 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 6 Apr 2023 15:48:34 +0000 (08:48 -0700)
extra/crontab/crontab-tests.factor
extra/crontab/crontab.factor

index 138c12293f6cf49e2e40fd853f9a4a27870f9470..51dcb92fa026dbb787b8c28d16903671701f1610 100644 (file)
@@ -176,3 +176,14 @@ CONSTANT: start-timestamp T{ timestamp
         "Sun, 21 Apr 2019 04:05:00 -0700"
     }
 } [ "5 4 * * 7" next-few-times ] unit-test
+
+! At 04:05 on every 3rd day-of-week from Monday through Sunday.
+{
+    {
+        "Sun, 24 Mar 2019 04:05:00 -0700"
+        "Mon, 25 Mar 2019 04:05:00 -0700"
+        "Thu, 28 Mar 2019 04:05:00 -0700"
+        "Sun, 31 Mar 2019 04:05:00 -0700"
+        "Mon, 1 Apr 2019 04:05:00 -0700"
+    }
+} [ "5 4 * * 1/3" next-few-times ] unit-test
index b90b69d6986df1180b399ee908d843d9fc9e3b62..d1eb4cde75c8a1e03df381bedcf6404afe8f8c8d 100644 (file)
@@ -2,8 +2,9 @@
 ! See https://factorcode.org/license.txt for BSD license
 
 USING: accessors arrays ascii assocs calendar calendar.english
-calendar.private combinators combinators.short-circuit io kernel
-literals math math.order math.parser ranges sequences splitting ;
+calendar.private circular combinators combinators.short-circuit
+io kernel literals math math.order math.parser ranges sequences
+sets sorting splitting ;
 
 IN: crontab
 
@@ -18,7 +19,7 @@ ERROR: invalid-cronentry value ;
             "/" split1 [
                 quot seq parse-value
                 dup length 1 = [ seq swap first ] [ 0 ] if
-                over length 1 -
+                over length dup 7 = [ [ <circular> ] 2dip ] [ 1 - ] if
             ] dip string>number <range> swap nths ] }
         { [ CHAR: - over member? ] [
             "-" split1 quot bi@ [a..b] ] }
@@ -67,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 ]
+        [ [ parse-day ] T{ range f 0 7 1 } parse-value members sort ]
         [ ]
     } spread cronentry boa check-cronentry ;
 
@@ -94,8 +95,8 @@ CONSTANT: aliases H{
         cronentry days>> first timestamp days-in-month +
     ] unless* day - :> days-to-day
 
-    cronentry days-of-week>> T{ range f 0 7 1 } =
-    cronentry days>> T{ range f 1 31 1 } = 2array
+    cronentry days-of-week>> length 7 =
+    cronentry days>> length 31 = 2array
     {
         { { f t } [ days-to-weekday ] }
         { { t f } [ days-to-day ] }