1 USING: calendar calendar.format crontab kernel math.order
7 now "*/1 * * * *" parse-cronentry next-time <=>
10 [ "0 0 30 2 *" parse-cronentry ] [ invalid-cronentry? ] must-fail-with
11 [ "0 0 31 4 *" parse-cronentry ] [ invalid-cronentry? ] must-fail-with
13 CONSTANT: start-timestamp T{ timestamp
18 { second 16+4353/8000 }
19 { gmt-offset T{ duration { hour -7 } } }
22 : next-few-times ( pattern -- timestamps )
23 parse-cronentry 5 start-timestamp next-times-after
24 [ timestamp>rfc822 ] map ;
29 "Sun, 24 Mar 2019 04:05:00 -0700"
30 "Mon, 25 Mar 2019 04:05:00 -0700"
31 "Tue, 26 Mar 2019 04:05:00 -0700"
32 "Wed, 27 Mar 2019 04:05:00 -0700"
33 "Thu, 28 Mar 2019 04:05:00 -0700"
35 } [ "5 4 * * *" next-few-times ] unit-test
40 "Thu, 1 Aug 2019 00:05:00 -0700"
41 "Fri, 2 Aug 2019 00:05:00 -0700"
42 "Sat, 3 Aug 2019 00:05:00 -0700"
43 "Sun, 4 Aug 2019 00:05:00 -0700"
44 "Mon, 5 Aug 2019 00:05:00 -0700"
46 } [ "5 0 * 8 *" next-few-times ] unit-test
48 ! At 14:15 on day-of-month 1.
51 "Mon, 1 Apr 2019 14:15:00 -0700"
52 "Wed, 1 May 2019 14:15:00 -0700"
53 "Sat, 1 Jun 2019 14:15:00 -0700"
54 "Mon, 1 Jul 2019 14:15:00 -0700"
55 "Thu, 1 Aug 2019 14:15:00 -0700"
57 } [ "15 14 1 * *" next-few-times ] unit-test
59 ! At 22:00 on every day-of-week from Monday through Friday.
62 "Mon, 25 Mar 2019 22:00:00 -0700"
63 "Tue, 26 Mar 2019 22:00:00 -0700"
64 "Wed, 27 Mar 2019 22:00:00 -0700"
65 "Thu, 28 Mar 2019 22:00:00 -0700"
66 "Fri, 29 Mar 2019 22:00:00 -0700"
68 } [ "0 22 * * 1-5" next-few-times ] unit-test
70 ! At minute 23 past every 2nd hour from 0 through 20.
73 "Sat, 23 Mar 2019 14:23:00 -0700"
74 "Sat, 23 Mar 2019 16:23:00 -0700"
75 "Sat, 23 Mar 2019 18:23:00 -0700"
76 "Sat, 23 Mar 2019 20:23:00 -0700"
77 "Sun, 24 Mar 2019 00:23:00 -0700"
79 } [ "23 0-20/2 * * *" next-few-times ] unit-test
84 "Sun, 24 Mar 2019 04:05:00 -0700"
85 "Sun, 31 Mar 2019 04:05:00 -0700"
86 "Sun, 7 Apr 2019 04:05:00 -0700"
87 "Sun, 14 Apr 2019 04:05:00 -0700"
88 "Sun, 21 Apr 2019 04:05:00 -0700"
90 } [ "5 4 * * sun" next-few-times ] unit-test
92 ! At minute 0 past hour 0 and 12 on day-of-month 1 in every 2nd month.
95 "Wed, 1 May 2019 00:00:00 -0700"
96 "Wed, 1 May 2019 12:00:00 -0700"
97 "Mon, 1 Jul 2019 00:00:00 -0700"
98 "Mon, 1 Jul 2019 12:00:00 -0700"
99 "Sun, 1 Sep 2019 00:00:00 -0700"
101 } [ "0 0,12 1 */2 *" next-few-times ] unit-test
103 ! At 04:00 on every day-of-month from 8 through 14.
106 "Mon, 8 Apr 2019 04:00:00 -0700"
107 "Tue, 9 Apr 2019 04:00:00 -0700"
108 "Wed, 10 Apr 2019 04:00:00 -0700"
109 "Thu, 11 Apr 2019 04:00:00 -0700"
110 "Fri, 12 Apr 2019 04:00:00 -0700"
112 } [ "0 4 8-14 * *" next-few-times ] unit-test
114 ! At 00:00 on day-of-month 1 and 15 and on Wednesday.
117 "Wed, 27 Mar 2019 00:00:00 -0700"
118 "Mon, 1 Apr 2019 00:00:00 -0700"
119 "Wed, 3 Apr 2019 00:00:00 -0700"
120 "Wed, 10 Apr 2019 00:00:00 -0700"
121 "Mon, 15 Apr 2019 00:00:00 -0700"
123 } [ "0 0 1,15 * 3" next-few-times ] unit-test
125 ! At 00:00 on Sunday.
128 "Sun, 24 Mar 2019 00:00:00 -0700"
129 "Sun, 31 Mar 2019 00:00:00 -0700"
130 "Sun, 7 Apr 2019 00:00:00 -0700"
131 "Sun, 14 Apr 2019 00:00:00 -0700"
132 "Sun, 21 Apr 2019 00:00:00 -0700"
134 } [ "@weekly" next-few-times ] unit-test
136 ! At 00:00 on day-of-month 29 in February.
139 "Sat, 29 Feb 2020 00:00:00 -0700"
140 "Thu, 29 Feb 2024 00:00:00 -0700"
141 "Tue, 29 Feb 2028 00:00:00 -0700"
142 "Sun, 29 Feb 2032 00:00:00 -0700"
143 "Fri, 29 Feb 2036 00:00:00 -0700"
145 } [ "0 0 29 2 *" next-few-times ] unit-test
147 ! At every 26th minute from 2 through 59 past hour 4.
150 "Sun, 24 Mar 2019 04:02:00 -0700"
151 "Sun, 24 Mar 2019 04:28:00 -0700"
152 "Sun, 24 Mar 2019 04:54:00 -0700"
153 "Mon, 25 Mar 2019 04:02:00 -0700"
154 "Mon, 25 Mar 2019 04:28:00 -0700"
156 } [ "2/26 4 * * *" next-few-times ] unit-test
158 ! At every 3rd minute from 5 through 20 past hour 4.
161 "Sun, 24 Mar 2019 04:05:00 -0700"
162 "Sun, 24 Mar 2019 04:08:00 -0700"
163 "Sun, 24 Mar 2019 04:11:00 -0700"
164 "Sun, 24 Mar 2019 04:14:00 -0700"
165 "Sun, 24 Mar 2019 04:17:00 -0700"
167 } [ "5-20/3 4 * * *" next-few-times ] unit-test
169 ! At 04:05 on Sunday.
172 "Sun, 24 Mar 2019 04:05:00 -0700"
173 "Sun, 31 Mar 2019 04:05:00 -0700"
174 "Sun, 7 Apr 2019 04:05:00 -0700"
175 "Sun, 14 Apr 2019 04:05:00 -0700"
176 "Sun, 21 Apr 2019 04:05:00 -0700"
178 } [ "5 4 * * 7" next-few-times ] unit-test
180 ! At 04:05 on every 3rd day-of-week from Monday through Sunday.
183 "Sun, 24 Mar 2019 04:05:00 -0700"
184 "Mon, 25 Mar 2019 04:05:00 -0700"
185 "Thu, 28 Mar 2019 04:05:00 -0700"
186 "Sun, 31 Mar 2019 04:05:00 -0700"
187 "Mon, 1 Apr 2019 04:05:00 -0700"
189 } [ "5 4 * * 1/3" next-few-times ] unit-test
191 ! At 04:05 on every 2nd day-of-month from 1 through 5.
194 "Mon, 1 Apr 2019 04:05:00 -0700"
195 "Wed, 3 Apr 2019 04:05:00 -0700"
196 "Fri, 5 Apr 2019 04:05:00 -0700"
197 "Wed, 1 May 2019 04:05:00 -0700"
198 "Fri, 3 May 2019 04:05:00 -0700"
200 } [ "5 4 1-5/2 * *" next-few-times ] unit-test