Skip to content

Commit

Permalink
crontab: fixing another case
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjbq7 committed Apr 6, 2023
1 parent 7ca96ba commit 8f980de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions extra/crontab/crontab-tests.factor
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions extra/crontab/crontab.factor
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] [
Expand Down Expand Up @@ -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 ;

Expand Down

0 comments on commit 8f980de

Please sign in to comment.