From: John Benediktsson Date: Sun, 3 Dec 2023 00:08:49 +0000 (-0800) Subject: crontab: allow start and end of ranges to be optional X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=9877489c175f888160d7a1ad5387dd3f3808fe9b crontab: allow start and end of ranges to be optional --- diff --git a/extra/crontab/crontab-tests.factor b/extra/crontab/crontab-tests.factor index 6874249741..f717350969 100644 --- a/extra/crontab/crontab-tests.factor +++ b/extra/crontab/crontab-tests.factor @@ -198,3 +198,25 @@ CONSTANT: start-timestamp T{ timestamp "Fri, 3 May 2019 04:05:00 -0700" } } [ "5 4 1-5/2 * *" next-few-times ] unit-test + +! The first 10 minutes of every 04:00 hour +{ + { + "Sun, 24 Mar 2019 04:00:00 -0700" + "Sun, 24 Mar 2019 04:01:00 -0700" + "Sun, 24 Mar 2019 04:02:00 -0700" + "Sun, 24 Mar 2019 04:03:00 -0700" + "Sun, 24 Mar 2019 04:04:00 -0700" + } +} [ "-10 4 * * *" next-few-times ] unit-test + +! The last 10 minutes of every 04:00 hour +{ + { + "Sun, 24 Mar 2019 04:50:00 -0700" + "Sun, 24 Mar 2019 04:51:00 -0700" + "Sun, 24 Mar 2019 04:52:00 -0700" + "Sun, 24 Mar 2019 04:53:00 -0700" + "Sun, 24 Mar 2019 04:54:00 -0700" + } +} [ "50- 4 * * *" next-few-times ] unit-test diff --git a/extra/crontab/crontab.factor b/extra/crontab/crontab.factor index 66521a5d70..1bbb9a9606 100644 --- a/extra/crontab/crontab.factor +++ b/extra/crontab/crontab.factor @@ -15,12 +15,16 @@ TUPLE: cronentry minutes hours days months days-of-week command ; ] 2dip ] [ 1 - ] if ] dip string>number swap nths ] } { [ CHAR: - over member? ] [ - "-" split1 quot bi@ [a..b] ] } + "-" split1 quot seq parse-range [a..b] ] } { [ CHAR: ~ over member? ] [ - "~" split1 quot bi@ [a..b] random 1array ] } + "~" split1 quot seq parse-range [a..b] random 1array ] } [ quot call 1array ] } cond members sort ; inline recursive