crontab: simplify (next-time-after) recursion.

windows-drag
John Benediktsson 2019-03-22 20:57:50 -07:00
parent 3afc3447b4
commit ffbb4c8289
1 changed files with 17 additions and 14 deletions

View File

@ -57,41 +57,44 @@ CONSTANT: aliases H{
:: (next-time-after) ( cronentry timestamp -- ) :: (next-time-after) ( cronentry timestamp -- )
f ! should we keep searching for a matching time
timestamp month>> :> month timestamp month>> :> month
cronentry months>> [ month >= ] find nip cronentry months>> [ month >= ] find nip
dup month = [ drop f ] [ dup month = [ drop ] [
[ cronentry months>> first timestamp 1 +year drop ] unless* [ cronentry months>> first timestamp 1 +year drop ] unless*
timestamp 1 >>day 0 >>hour 0 >>minute month<< t timestamp 1 >>day 0 >>hour 0 >>minute month<< drop t
] if [ cronentry timestamp (next-time-after) ] when ] if
timestamp day>> :> day timestamp day>> :> day
cronentry days>> [ day >= ] find nip cronentry days>> [ day >= ] find nip
dup day = [ drop f ] [ dup day = [ drop ] [
[ cronentry days>> first timestamp 1 +month drop ] unless* [ cronentry days>> first timestamp 1 +month drop ] unless*
timestamp 0 >>hour 0 >>minute day<< t timestamp 0 >>hour 0 >>minute day<< drop t
] if [ cronentry timestamp (next-time-after) ] when ] if
timestamp day-of-week :> weekday timestamp day-of-week :> weekday
cronentry days-of-week>> [ weekday >= ] find nip [ cronentry days-of-week>> [ weekday >= ] find nip [
cronentry days-of-week>> first 7 + cronentry days-of-week>> first 7 +
] unless* weekday - [ ] unless* weekday - [
timestamp 0 >>hour 0 >>minute swap +day drop timestamp 0 >>hour 0 >>minute swap +day 2drop t
cronentry timestamp (next-time-after)
] unless-zero ] unless-zero
timestamp hour>> :> hour timestamp hour>> :> hour
cronentry hours>> [ hour >= ] find nip cronentry hours>> [ hour >= ] find nip
dup hour = [ drop f ] [ dup hour = [ drop ] [
[ cronentry hours>> first timestamp 1 +day drop ] unless* [ cronentry hours>> first timestamp 1 +day drop ] unless*
timestamp 0 >>minute hour<< t timestamp 0 >>minute hour<< drop t
] if [ cronentry timestamp (next-time-after) ] when ] if
timestamp minute>> :> minute timestamp minute>> :> minute
cronentry minutes>> [ minute >= ] find nip cronentry minutes>> [ minute >= ] find nip
dup minute = [ drop f ] [ dup minute = [ drop ] [
[ cronentry minutes>> first timestamp 1 +hour drop ] unless* [ cronentry minutes>> first timestamp 1 +hour drop ] unless*
timestamp minute<< t timestamp minute<< drop t
] if [ cronentry timestamp (next-time-after) ] when ; ] if
[ cronentry timestamp (next-time-after) ] when ;
PRIVATE> PRIVATE>