]> gitweb.factorcode.org Git - factor.git/blob - extra/crontab/crontab-tests.factor
Reformat
[factor.git] / extra / crontab / crontab-tests.factor
1 USING: calendar calendar.format crontab kernel math.order
2 sequences tools.test ;
3
4 IN: crontab.tests
5
6 { +lt+ } [
7     now "*/1 * * * *" parse-cronentry next-time <=>
8 ] unit-test
9
10 [ "0 0 30 2 *" parse-cronentry ] [ invalid-cronentry? ] must-fail-with
11 [ "0 0 31 4 *" parse-cronentry ] [ invalid-cronentry? ] must-fail-with
12
13 CONSTANT: start-timestamp T{ timestamp
14     { year 2019 }
15     { month 3 }
16     { day 23 }
17     { hour 14 }
18     { second 16+4353/8000 }
19     { gmt-offset T{ duration { hour -7 } } }
20 }
21
22 : next-few-times ( pattern -- timestamps )
23     parse-cronentry 5 start-timestamp next-times-after
24     [ timestamp>rfc822 ] map ;
25
26 ! At 04:05.
27 {
28     {
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"
34     }
35 } [ "5 4 * * *" next-few-times ] unit-test
36
37 ! At 00:05 in August.
38 {
39     {
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"
45     }
46 } [ "5 0 * 8 *" next-few-times ] unit-test
47
48 ! At 14:15 on day-of-month 1.
49 {
50     {
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"
56     }
57 } [ "15 14 1 * *" next-few-times ] unit-test
58
59 ! At 22:00 on every day-of-week from Monday through Friday.
60 {
61     {
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"
67     }
68 } [ "0 22 * * 1-5" next-few-times ] unit-test
69
70 ! At minute 23 past every 2nd hour from 0 through 20.
71 {
72     {
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"
78     }
79 } [ "23 0-20/2 * * *" next-few-times ] unit-test
80
81 ! At 04:05 on Sunday.
82 {
83     {
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"
89     }
90 } [ "5 4 * * sun" next-few-times ] unit-test
91
92 ! At minute 0 past hour 0 and 12 on day-of-month 1 in every 2nd month.
93 {
94     {
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"
100     }
101 } [ "0 0,12 1 */2 *" next-few-times ] unit-test
102
103 ! At 04:00 on every day-of-month from 8 through 14.
104 {
105     {
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"
111     }
112 } [ "0 4 8-14 * *" next-few-times ] unit-test
113
114 ! At 00:00 on day-of-month 1 and 15 and on Wednesday.
115 {
116     {
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"
122     }
123 } [ "0 0 1,15 * 3" next-few-times ] unit-test
124
125 ! At 00:00 on Sunday.
126 {
127     {
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"
133     }
134 } [ "@weekly" next-few-times ] unit-test
135
136 ! At 00:00 on day-of-month 29 in February.
137 {
138     {
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"
144     }
145 } [ "0 0 29 2 *" next-few-times ] unit-test