runt 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +107 -71
- data/LICENSE.txt +43 -43
- data/README +100 -94
- data/Rakefile +119 -120
- data/TODO +11 -20
- data/doc/tutorial_schedule.rdoc +84 -51
- data/doc/tutorial_te.rdoc +190 -190
- data/lib/runt.rb +219 -110
- data/lib/runt/daterange.rb +74 -74
- data/lib/runt/dprecision.rb +141 -137
- data/lib/runt/pdate.rb +153 -126
- data/lib/runt/schedule.rb +88 -89
- data/lib/runt/temporalexpression.rb +695 -524
- data/setup.rb +1331 -1331
- data/site/blue-robot3.css +131 -131
- data/site/index.html +94 -93
- data/site/runt-logo.psd +0 -0
- data/test/daterangetest.rb +87 -87
- data/test/dprecisiontest.rb +55 -45
- data/test/icalendartest.rb +524 -0
- data/test/pdatetest.rb +117 -104
- data/test/runttest.rb +101 -0
- data/test/scheduletest.rb +148 -88
- data/test/temporalexpressiontest.rb +612 -402
- metadata +56 -43
- data/test/alltests.rb +0 -10
@@ -1,402 +1,612 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'test/unit'
|
4
|
-
require 'runt'
|
5
|
-
require 'date'
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
include
|
16
|
-
|
17
|
-
|
18
|
-
def test_collection_te
|
19
|
-
#base class that should always return false
|
20
|
-
expr = Collection.new
|
21
|
-
assert(!expr.include?(Date.today))
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
assert
|
61
|
-
assert
|
62
|
-
|
63
|
-
assert
|
64
|
-
end
|
65
|
-
|
66
|
-
def
|
67
|
-
|
68
|
-
expr1
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
#
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
assert(
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
expr1
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
assert(
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
#
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
#
|
159
|
-
|
160
|
-
#
|
161
|
-
|
162
|
-
#
|
163
|
-
|
164
|
-
#
|
165
|
-
|
166
|
-
|
167
|
-
assert(!
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
end
|
180
|
-
|
181
|
-
def
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
assert(
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
#
|
208
|
-
|
209
|
-
#
|
210
|
-
|
211
|
-
#
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
assert(
|
222
|
-
#
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
#
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
#
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
#
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
#
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
assert(
|
333
|
-
assert(
|
334
|
-
assert(
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
assert
|
384
|
-
|
385
|
-
assert
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
assert
|
393
|
-
assert
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'runt'
|
5
|
+
require 'date'
|
6
|
+
require 'time'
|
7
|
+
|
8
|
+
$DEBUG=false
|
9
|
+
|
10
|
+
# Unit tests for TExpr classes
|
11
|
+
# Author:: Matthew Lipper
|
12
|
+
|
13
|
+
class TExprTest < Test::Unit::TestCase
|
14
|
+
|
15
|
+
include Runt
|
16
|
+
include DPrecision
|
17
|
+
|
18
|
+
def test_collection_te
|
19
|
+
#base class that should always return false
|
20
|
+
expr = Collection.new
|
21
|
+
assert(!expr.include?(Date.today))
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
def test_collection_te_to_s
|
26
|
+
assert_equal 'empty', Collection.new.to_s
|
27
|
+
assert_equal 'empty', Collection.new.to_s{['b','oo']}
|
28
|
+
expr = Collection.new
|
29
|
+
dim = DIMonth.new(First,Tuesday)
|
30
|
+
expr.expressions << dim
|
31
|
+
assert_equal 'ff' + dim.to_s, expr.to_s{['ff','nn']}
|
32
|
+
red = REDay.new(0,0,6,30)
|
33
|
+
expr.expressions << red
|
34
|
+
assert_equal 'ff' + dim.to_s + 'nn' + red.to_s, expr.to_s{['ff','nn']}
|
35
|
+
wim = WIMonth.new(Second_to_last)
|
36
|
+
expr.expressions << wim
|
37
|
+
assert_equal 'ff' + dim.to_s + 'nn' + red.to_s + 'nn' + wim.to_s, expr.to_s{['ff','nn']}
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_union_te_to_s
|
41
|
+
dim = DIMonth.new(First,Tuesday)
|
42
|
+
red = REDay.new(0,0,6,30)
|
43
|
+
expr = dim | red
|
44
|
+
assert_equal 'every ' + dim.to_s + ' or ' + red.to_s, expr.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_union_te
|
48
|
+
#midnight to 6:30am AND/OR first Tuesday of the month
|
49
|
+
expr = REDay.new(0,0,6,30) | DIMonth.new(First,Tuesday)
|
50
|
+
assert(expr.include?(PDate.day(2004,1,6))) #January 6th, 2004 (First Tuesday)
|
51
|
+
assert(expr.include?(PDate.hour(1966,2,8,4))) #4am (February, 8th, 1966 - ignored)
|
52
|
+
assert(!expr.include?(PDate.min(2030,7,4,6,31))) #6:31am, July, 4th, 2030
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_spec_te_include
|
56
|
+
expr1 = Spec.new(PDate.day(2003,12,30))
|
57
|
+
expr2 = Spec.new(PDate.day(2004,1,1))
|
58
|
+
assert expr1.include?(Date.new(2003,12,30))
|
59
|
+
assert !expr1.include?(Date.new(2003,12,31))
|
60
|
+
assert expr2.include?(Date.new(2004,1,1))
|
61
|
+
assert !expr2.include?(Date.new(2003,1,1))
|
62
|
+
expr3 = Spec.new(DateTime.civil(2006,3,11,8,30))
|
63
|
+
assert expr3.include?(DateTime.civil(2006,3,11,8,30))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_spec_te_to_s
|
67
|
+
pdate = PDate.day(2003,12,30)
|
68
|
+
expr1 = Spec.new(pdate)
|
69
|
+
assert_equal expr1.to_s, pdate.to_s
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_rspec_te
|
73
|
+
#NOTE:
|
74
|
+
#Using standard range functionality like the following:
|
75
|
+
#... expr1 = RSpec.new(r_start..r_end)
|
76
|
+
#... assert(expr1.include?((r_start+10)..(r_end-10)))
|
77
|
+
#will work. However, it takes a LONG time to evaluate if range is large
|
78
|
+
#and/or precision is small. Use DateRange instead
|
79
|
+
|
80
|
+
r_start = PDate.sec(2004,2,29,16,24,12)
|
81
|
+
r_end = PDate.sec(2004,3,2,4,22,58)
|
82
|
+
#inclusive range equivalent to r_start..r_end
|
83
|
+
expr1 = RSpec.new(DateRange.new(r_start,r_end))
|
84
|
+
assert(expr1.include?(PDate.sec(2004,2,29,16,24,12)))
|
85
|
+
assert(expr1.include?(PDate.sec(2004,3,2,4,22,58)))
|
86
|
+
assert(expr1.include?(DateTime.new(2004,3,1,23,00)))
|
87
|
+
assert(!expr1.include?(DateTime.new(2004,3,2,4,22,59)))
|
88
|
+
assert(!expr1.include?(Date.new(2003,3,1)))
|
89
|
+
#exclusive range equivalent to r_start...r_end
|
90
|
+
expr2 = RSpec.new(DateRange.new(r_start,r_end,true))
|
91
|
+
assert(expr2.include?(PDate.sec(2004,2,29,16,24,12)))
|
92
|
+
assert(!expr2.include?(PDate.sec(2004,3,2,4,22,58)))
|
93
|
+
r_sub = DateRange.new( (r_start+10), (r_end-10) )
|
94
|
+
assert(expr1.include?(r_sub))
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_rspec_te_to_s
|
98
|
+
range = DateRange.new(PDate.new(2006,2,25),PDate.new(2006,4,8))
|
99
|
+
expr = RSpec.new(range)
|
100
|
+
assert_equal expr.to_s, range.to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_intersection_te
|
104
|
+
#Should match the first Sunday of March and April
|
105
|
+
expr1 = REYear.new(3,4) & DIMonth.new(First,Sunday)
|
106
|
+
assert(expr1.include?(PDate.new(2004,3,7))) #Sunday, March 7th, 2004
|
107
|
+
assert(!expr1.include?(PDate.new(2004,4,1))) #First Sunday in February, 2004
|
108
|
+
expr2 = REWeek.new(Mon,Fri) & REDay.new(8,00,8,30)
|
109
|
+
assert(expr2.include?( PDate.new(2004,5,4,8,06)))
|
110
|
+
assert(!expr2.include?(PDate.new(2004,5,1,8,06)))
|
111
|
+
assert(!expr2.include?(PDate.new(2004,5,3,9,06)))
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_intersection_te_to_s
|
115
|
+
dim = DIMonth.new(First,Tuesday)
|
116
|
+
red = REDay.new(0,0,6,30)
|
117
|
+
expr = dim & red
|
118
|
+
assert_equal 'every ' + dim.to_s + ' and ' + red.to_s, expr.to_s
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_difference_te
|
122
|
+
#Should match for 8:30 pm to 11:04 pm
|
123
|
+
diff_expr = REDay.new(20,30,00,00) - REDay.new(23,04,6,20)
|
124
|
+
#8:45 pm (May 1st, 2003 - ignored)
|
125
|
+
assert(diff_expr.include?(PDate.new(2003,5,1,20,45)))
|
126
|
+
#11:05 pm (February 1st, 2004 - ignored)
|
127
|
+
assert(!diff_expr.include?(PDate.new(2004,2,1,23,05)))
|
128
|
+
#8:00 pm (May 1st, 2003 - ignored)
|
129
|
+
assert(!diff_expr.include?(PDate.new(2003,5,1,20,00)))
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_diff_to_s
|
133
|
+
rey1 = REYear.new 3,1,6,2
|
134
|
+
rey2 = REYear.new 4,15,5,20
|
135
|
+
expr = rey1 - rey2
|
136
|
+
assert_equal rey1.to_s + ' except for ' + rey2.to_s, expr.to_s
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
def test_memorial_day
|
141
|
+
# Monday through Friday, from 9am to 5pm
|
142
|
+
job = REWeek.new(Mon,Fri) & REDay.new(9,00,17,00)
|
143
|
+
# Memorial Day (U.S.)
|
144
|
+
memorial_day = REYear.new(5) & DIMonth.new(Last,Monday)
|
145
|
+
# May 29th, 2006
|
146
|
+
last_monday_in_may = PDate.min(2006,5,29,10,12)
|
147
|
+
# Before
|
148
|
+
assert job.include?(last_monday_in_may)
|
149
|
+
assert job.include?(PDate.min(20006,5,30,14,00))
|
150
|
+
# Add Diff expression
|
151
|
+
job_with_holiday = job - last_monday_in_may
|
152
|
+
assert !job_with_holiday.include?(last_monday_in_may)
|
153
|
+
# Still have to work on Tuesday
|
154
|
+
assert job.include?(PDate.min(20006,5,30,14,00))
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_day_in_month_te
|
158
|
+
#Friday, January 16th 2004
|
159
|
+
dt1 = Date.civil(2004,1,16)
|
160
|
+
#Friday, January 9th 2004
|
161
|
+
dt2 = Date.civil(2004,1,9)
|
162
|
+
#third Friday of the month
|
163
|
+
expr1 = DIMonth.new(Third,Friday)
|
164
|
+
#second Friday of the month
|
165
|
+
expr2 = DIMonth.new(Second,Friday)
|
166
|
+
assert(expr1.include?(dt1))
|
167
|
+
assert(!expr1.include?(dt2))
|
168
|
+
assert(expr2.include?(dt2))
|
169
|
+
assert(!expr2.include?(dt1))
|
170
|
+
#Sunday, January 25th 2004
|
171
|
+
dt3 = Date.civil(2004,1,25)
|
172
|
+
#last Sunday of the month
|
173
|
+
expr3 = DIMonth.new(Last_of,Sunday)
|
174
|
+
assert(expr3.include?(dt3))
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_day_in_month_te_to_s
|
178
|
+
assert_equal 'last Sunday of the month', DIMonth.new(Last_of,Sunday).to_s
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_day_in_week_te
|
182
|
+
#Friday (woo-hoo!)
|
183
|
+
expr = DIWeek.new(Friday)
|
184
|
+
#Friday, January 9th 2004
|
185
|
+
assert(expr.include?(PDate.new(2004,1,9)))
|
186
|
+
#Friday, January 16th 2004
|
187
|
+
assert(expr.include?(PDate.new(2004,1,16)))
|
188
|
+
#Monday, January 12th 2004
|
189
|
+
assert(!expr.include?(PDate.new(2004,1,12)))
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_day_in_week_te
|
193
|
+
assert_equal 'Friday', DIWeek.new(Friday).to_s
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_week_in_month_te
|
197
|
+
expr = WIMonth.new(Third)
|
198
|
+
assert(expr.include?(PDate.day(2004,2,19)))
|
199
|
+
assert(!expr.include?(PDate.day(2004,2,29)))
|
200
|
+
expr2 = WIMonth.new(Last_of)
|
201
|
+
assert(expr2.include?(PDate.day(2004,2,29)))
|
202
|
+
expr3 = WIMonth.new(Second_to_last)
|
203
|
+
assert(expr3.include?(PDate.day(2004,2,22)))
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_range_each_year_te
|
207
|
+
# November 1st, 1961
|
208
|
+
dt1 = Date.civil(1961,11,1)
|
209
|
+
#June, 1986
|
210
|
+
dt2 = PDate::month(1986,6)
|
211
|
+
#November and December
|
212
|
+
expr1 = REYear.new(11,12)
|
213
|
+
#May 31st through September 6th
|
214
|
+
expr2 = REYear.new(5,31,9,6)
|
215
|
+
assert(expr1.include?(dt1))
|
216
|
+
assert(!expr1.include?(dt2))
|
217
|
+
assert(expr2.include?(dt2))
|
218
|
+
#August
|
219
|
+
expr3 = REYear.new(8)
|
220
|
+
assert(!expr3.include?(dt1))
|
221
|
+
assert(!expr3.include?(dt2))
|
222
|
+
#August 6th, 2004
|
223
|
+
dt3 = Date::new(2004,8,6)
|
224
|
+
assert(expr3.include?(dt3))
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_range_each_year_te_to_s
|
228
|
+
assert_equal 'June 1st through July 2nd', REYear.new(6, 1, 7, 2).to_s
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_range_each_day_te
|
232
|
+
#noon to 4:30pm
|
233
|
+
expr1 = REDay.new(12,0,16,30)
|
234
|
+
#3:15 pm (May 8th, 2012 - ignored)
|
235
|
+
assert(expr1.include?(PDate.hour(2012,5,8,15,15)))
|
236
|
+
#4:30 pm (April 18th, 1922 - ignored)
|
237
|
+
assert(expr1.include?(PDate.hour(1922,4,18,16,30)))
|
238
|
+
#noon (June 5th, 1975 - ignored)
|
239
|
+
assert(expr1.include?(PDate.hour(1975,6,5,12,0)))
|
240
|
+
#3:15 am (May 8th, 2012 - ignored)
|
241
|
+
assert(!expr1.include?(PDate.hour(2012,5,8,3,15)))
|
242
|
+
#8:30pm to 12:00 midnite
|
243
|
+
expr2 = REDay.new(20,30,00,00)
|
244
|
+
#9:00 pm (January 28th, 2004 - ignored)
|
245
|
+
assert(expr2.include?(PDate.min(2004,1,28,21,00)))
|
246
|
+
#12:00 am (January 28th, 2004 - ignored)
|
247
|
+
assert(expr2.include?(PDate.min(2004,1,28,0,0)))
|
248
|
+
#12:01 am (January 28th, 2004 - ignored)
|
249
|
+
assert(!expr2.include?(PDate.min(2004,1,28,0,01)))
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_range_each_day_te_again
|
253
|
+
dr = DateRange.new(PDate.day(2005,9,19),PDate.day(2005,9,20))
|
254
|
+
red = REDay.new(8,0,10,0)
|
255
|
+
result = false
|
256
|
+
dr.each do |interval|
|
257
|
+
result = red.include?(interval)
|
258
|
+
break if result
|
259
|
+
end
|
260
|
+
assert(result)
|
261
|
+
end
|
262
|
+
|
263
|
+
def test_range_each_day_te_to_s
|
264
|
+
assert_equal 'from 11:10PM to 01:20AM daily', REDay.new(23,10,1,20).to_s
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_range_each_week_te
|
268
|
+
assert_raises(ArgumentError){ expr = REWeek.new(10,4) }
|
269
|
+
expr1 = REWeek.new(Mon,Fri) & REDay.new(8,00,8,30)
|
270
|
+
assert(!expr1.include?(PDate.new(2004,5,1,8,06)))
|
271
|
+
#Sunday through Thursday
|
272
|
+
expr2 = REWeek.new(0,4)
|
273
|
+
assert(expr2.include?(PDate.min(2004,2,19,23,59,59)))
|
274
|
+
assert(!expr2.include?(PDate.min(2004,2,20,0,0,0)))
|
275
|
+
end
|
276
|
+
|
277
|
+
def test_range_each_week_te
|
278
|
+
#Friday through Tuesday
|
279
|
+
expr = Runt::REWeek.new(5,2)
|
280
|
+
|
281
|
+
assert expr.include?(Time.mktime(2007,9,28,0,0,0)), "#{expr.inspect} should include Fri 12am"
|
282
|
+
assert expr.include?(Time.mktime(2007,9,25,11,59,59)),"#{expr.inspect} should include Tue 11:59pm"
|
283
|
+
assert ! expr.include?(Time.mktime(2007,9,26,0,0,0)), "#{expr.inspect} should not include Wed 12am"
|
284
|
+
assert ! expr.include?(Time.mktime(2007,9,27,6,59,59)), "#{expr.inspect} should not include Thurs 6:59am"
|
285
|
+
assert ! expr.include?(Time.mktime(2007,9,27,11,59,0)), "#{expr.inspect} should not include Thurs 1159am"
|
286
|
+
assert expr.include?(Time.mktime(2007,9,29,11,0,0)), "#{expr.inspect} should include Sat 11am"
|
287
|
+
assert expr.include?(Time.mktime(2007,9,29,0,0,0)), "#{expr.inspect} should include Sat midnight"
|
288
|
+
assert expr.include?(Time.mktime(2007,9,29,23,59,59)), "#{expr.inspect} should include Saturday one minute before midnight"
|
289
|
+
assert expr.include?(Time.mktime(2007,9,30,23,59,59)), "#{expr.inspect} should include Sunday one minute before midnight"
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_range_each_week_te_to_s
|
293
|
+
assert_equal 'all week', REWeek.new(Tuesday,Tuesday).to_s
|
294
|
+
assert_equal 'Thursday through Saturday', REWeek.new(Thursday,Saturday).to_s
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_combined_te
|
298
|
+
#This is a hack.....
|
299
|
+
#In the U.S., Memorial Day begins the last Monday of May
|
300
|
+
#
|
301
|
+
#The month of May
|
302
|
+
may=REYear.new(5)
|
303
|
+
#Monday through Saturday
|
304
|
+
monday_to_saturday = REWeek.new(1,6)
|
305
|
+
#Last week of (any) month
|
306
|
+
last_week_in = WIMonth.new(Last_of)
|
307
|
+
#So, to say 'starting from the last Monday in May',
|
308
|
+
#we need to select just that last week of May begining with
|
309
|
+
#the Monday of that week
|
310
|
+
last_week_of_may = may & monday_to_saturday & last_week_in
|
311
|
+
|
312
|
+
#This is another hack similar to the above, except instead of selecting a range
|
313
|
+
#starting at the begining of the month, we need to select only the time period in
|
314
|
+
#September up until Labor Day.
|
315
|
+
#
|
316
|
+
#In the U.S., Labor Day is the first Monday in September
|
317
|
+
#
|
318
|
+
#The month of September
|
319
|
+
september=REYear.new(9)
|
320
|
+
#First week of (any) month
|
321
|
+
first_week_in = WIMonth.new(First)
|
322
|
+
entire_first_week_of_september = september & first_week_in
|
323
|
+
#To exclude everything in the first week which occurs on or after Monday.
|
324
|
+
first_week_of_september=entire_first_week_of_september - monday_to_saturday
|
325
|
+
#June through August
|
326
|
+
june_through_august=REYear.new(6,First,8)
|
327
|
+
assert(june_through_august.include?(PDate.day(2004,7,4)))
|
328
|
+
#Finally!
|
329
|
+
summer_time = last_week_of_may | first_week_of_september | june_through_august
|
330
|
+
|
331
|
+
#Will work, but will be incredibly slow:
|
332
|
+
# assert(summer_time.include?(PDate.min(2004,5,31,0,0)))
|
333
|
+
assert(summer_time.include?(PDate.day(2004,5,31,0,0)))
|
334
|
+
assert(summer_time.include?(PDate.day(2004,7,4)))
|
335
|
+
#also works...also slow:
|
336
|
+
# assert(!summer_time.include?(PDate.min(2004,9,6,0,0)))
|
337
|
+
assert(!summer_time.include?(PDate.hour(2004,9,6,0,0)))
|
338
|
+
|
339
|
+
end
|
340
|
+
def test_nyc_parking_te
|
341
|
+
|
342
|
+
#Monday, Wednesday, Friday
|
343
|
+
mon_wed_fri = DIWeek.new(Mon) | \
|
344
|
+
DIWeek.new(Wed) | \
|
345
|
+
DIWeek.new(Fri)
|
346
|
+
|
347
|
+
|
348
|
+
#Wednesday (at 7:15pm - ignored)
|
349
|
+
assert(mon_wed_fri.include?(DateTime.new(2004,3,10,19,15)))
|
350
|
+
|
351
|
+
#Sunday (at 9:00am - ignored)
|
352
|
+
assert(!mon_wed_fri.include?(DateTime.new(2004,3,14,9,00)))
|
353
|
+
|
354
|
+
#8am to 11am
|
355
|
+
eight_to_eleven = REDay.new(8,00,11,00)
|
356
|
+
|
357
|
+
#=> Mon,Wed,Fri - 8am to 11am
|
358
|
+
expr1 = mon_wed_fri & eight_to_eleven
|
359
|
+
|
360
|
+
#Tuesdays, Thursdays
|
361
|
+
tues_thurs = DIWeek.new(Tue) | DIWeek.new(Thu)
|
362
|
+
|
363
|
+
#11:30am to 2pm
|
364
|
+
eleven_thirty_to_two = REDay.new(11,30,14,00)
|
365
|
+
|
366
|
+
#Noon (on Monday - ignored)
|
367
|
+
assert(eleven_thirty_to_two.include?(DateTime.new(2004,3,8,12,00)))
|
368
|
+
|
369
|
+
#Midnite (on Thursday - ignored)
|
370
|
+
assert(!eleven_thirty_to_two.include?(DateTime.new(2004,3,11,00,00)))
|
371
|
+
|
372
|
+
|
373
|
+
#=> Tues,Thurs - 11:30am to 2pm
|
374
|
+
expr2 = tues_thurs & eleven_thirty_to_two
|
375
|
+
|
376
|
+
#
|
377
|
+
#Sigh...now if I can only get my dad to remember this...
|
378
|
+
#
|
379
|
+
parking_ticket = expr1 | expr2
|
380
|
+
|
381
|
+
assert(parking_ticket.include?(DateTime.new(2004,3,11,12,15)))
|
382
|
+
assert(parking_ticket.include?(DateTime.new(2004,3,10,9,15)))
|
383
|
+
assert(parking_ticket.include?(DateTime.new(2004,3,10,8,00)))
|
384
|
+
|
385
|
+
assert(!parking_ticket.include?(DateTime.new(2004,3,11,1,15)))
|
386
|
+
|
387
|
+
# Simplified
|
388
|
+
e1 = (DIWeek.new(Mon) | DIWeek.new(Wed) | DIWeek.new(Fri)) & REDay.new(8,00,11,00)
|
389
|
+
e2 = (DIWeek.new(Tue) | DIWeek.new(Thu)) & REDay.new(11,30,14,00)
|
390
|
+
ticket = expr1 | expr2
|
391
|
+
assert(ticket.include?(DateTime.new(2004,3,11,12,15)))
|
392
|
+
assert(ticket.include?(DateTime.new(2004,3,10,9,15)))
|
393
|
+
assert(ticket.include?(DateTime.new(2004,3,10,8,00)))
|
394
|
+
assert(!ticket.include?(DateTime.new(2004,3,11,1,15)))
|
395
|
+
end
|
396
|
+
|
397
|
+
def test_re_month_te
|
398
|
+
# October 22nd, 2005
|
399
|
+
dt1 = Date.civil(2005,10,22)
|
400
|
+
# The 20th through the 29th of any month
|
401
|
+
expr1 = REMonth.new(20,29)
|
402
|
+
assert(expr1.include?(dt1))
|
403
|
+
assert(!expr1.include?(PDate.new(2010,12,12)))
|
404
|
+
# August 17th, 1975
|
405
|
+
dt2 = Date.civil(1975,8,17)
|
406
|
+
# The 17th of any month
|
407
|
+
expr2 = REMonth.new(17)
|
408
|
+
assert(expr2.include?(dt2))
|
409
|
+
assert(!expr2.include?(dt1))
|
410
|
+
end
|
411
|
+
|
412
|
+
###
|
413
|
+
# Dates functionality & tests contributed by Emmett Shear
|
414
|
+
###
|
415
|
+
def test_day_in_month_dates
|
416
|
+
date_range = Date.civil(2005, 1, 1)..Date.civil(2005, 12, 31)
|
417
|
+
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
418
|
+
expr = DIMonth.new(First, Tuesday)
|
419
|
+
dates = expr.dates(date_range)
|
420
|
+
assert dates.size == 12
|
421
|
+
dates.each do |d|
|
422
|
+
assert d.wday == 2 # tuesday
|
423
|
+
assert d.day < 8 # in the first week
|
424
|
+
end
|
425
|
+
expr2 = DIMonth.new(Last, Friday)
|
426
|
+
dates2 = expr2.dates(date_range)
|
427
|
+
assert dates2.size == 12
|
428
|
+
dates2.each do |d|
|
429
|
+
assert d.wday == 5 # friday
|
430
|
+
assert d.day > month_days[d.month-1] - 8 # last week
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
def test_day_in_week_dates
|
435
|
+
date_range = Date.civil(2005, 1, 1)..Date.civil(2005, 1, 31)
|
436
|
+
expr = DIWeek.new(Sunday)
|
437
|
+
dates = expr.dates(date_range)
|
438
|
+
assert( dates.size == 5 )
|
439
|
+
assert( dates.include?( Date.civil(2005, 1, 16) ) )
|
440
|
+
assert( dates.include?( Date.civil(2005, 1, 30) ) )
|
441
|
+
end
|
442
|
+
|
443
|
+
def test_union_dates
|
444
|
+
date_range = Date.civil(2005, 1, 1)..Date.civil(2005, 12, 31)
|
445
|
+
month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
446
|
+
expr = DIMonth.new(Last, Friday) | DIMonth.new(1, Tuesday)
|
447
|
+
dates = expr.dates(date_range)
|
448
|
+
assert dates.size == 24
|
449
|
+
dates.each do |d|
|
450
|
+
unless (d.wday == 2 and d.day < 8) or \
|
451
|
+
(d.wday == 5 and d.day > month_days[d.month-1] - 8)
|
452
|
+
assert false, d.to_s
|
453
|
+
end
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
def test_intersection_dates
|
458
|
+
date_range = Date.civil(2005, 1, 1)..Date.civil(2005, 12, 31)
|
459
|
+
expr = DIWeek.new(Sunday) & DIMonth.new(Second, Sunday)
|
460
|
+
dates = expr.dates(date_range)
|
461
|
+
assert( dates.size == 12 )
|
462
|
+
other_dates = DIMonth.new(Second, Sunday).dates(date_range)
|
463
|
+
dates.each { |d| assert( other_dates.include?(d) ) }
|
464
|
+
end
|
465
|
+
|
466
|
+
def test_range_each_week_dates
|
467
|
+
date_range = Date.civil(2005, 1, 1)..Date.civil(2005, 1, 31)
|
468
|
+
expr = REWeek.new(3, 5)
|
469
|
+
dates = expr.dates(date_range)
|
470
|
+
assert dates.size == 12
|
471
|
+
end
|
472
|
+
|
473
|
+
def test_range_each_year_dates
|
474
|
+
date_range = Date.civil(2004, 5, 1)..Date.civil(2006, 5, 4)
|
475
|
+
expr = REYear.new(4, 28, 5, 6)
|
476
|
+
dates = expr.dates(date_range)
|
477
|
+
assert dates.size == 22, dates.size
|
478
|
+
end
|
479
|
+
|
480
|
+
def test_week_in_month_dates
|
481
|
+
date_range = Date.civil(2005, 1, 1)..Date.civil(2005, 2, 28)
|
482
|
+
expr = WIMonth.new(2)
|
483
|
+
dates = expr.dates(date_range)
|
484
|
+
assert dates.size == 14, dates.size
|
485
|
+
assert dates.first.mday == 8
|
486
|
+
assert dates.last.mday == 14
|
487
|
+
expr_2 = WIMonth.new(Last)
|
488
|
+
dates_2 = expr_2.dates(date_range)
|
489
|
+
assert dates_2.size == 14, dates_2.size
|
490
|
+
assert dates_2.first.mday == 25
|
491
|
+
assert dates_2.last.mday == 28
|
492
|
+
end
|
493
|
+
|
494
|
+
def test_week_in_month_to_s
|
495
|
+
assert_equal 'last week of any month', WIMonth.new(Last).to_s
|
496
|
+
end
|
497
|
+
|
498
|
+
def test_range_each_month_dates
|
499
|
+
date_range = Date.civil(2005, 1, 7)..Date.civil(2005, 1, 15)
|
500
|
+
expr = REMonth.new(5, 9)
|
501
|
+
dates = expr.dates(date_range)
|
502
|
+
assert dates.size == 3, dates.size
|
503
|
+
assert false if dates.include? Date.civil(2005, 1, 6)
|
504
|
+
end
|
505
|
+
|
506
|
+
def test_range_each_month_to_s
|
507
|
+
assert_equal 'from the 2nd to the 5th monthly',REMonth.new(2,5).to_s
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_diff_dates
|
511
|
+
date_range = Date.civil(2005, 1, 1)..Date.civil(2005, 1, 31)
|
512
|
+
expr = REYear.new(1, 1, 1, 31) - REMonth.new(7, 15)
|
513
|
+
dates = expr.dates(date_range)
|
514
|
+
assert dates.size == 22, dates.size
|
515
|
+
end
|
516
|
+
|
517
|
+
def test_day_interval_te
|
518
|
+
date1 = Date.civil(2005,10,28)
|
519
|
+
# Match every 8 days
|
520
|
+
expr = DayIntervalTE.new(date1, 8)
|
521
|
+
assert expr.include?((date1 + 8))
|
522
|
+
assert expr.include?((date1 + 16))
|
523
|
+
assert expr.include?((date1 + 64))
|
524
|
+
# Now use DateTime
|
525
|
+
date2 = DateTime.now
|
526
|
+
# Match every 6 days
|
527
|
+
expr2 = DayIntervalTE.new(date2, 6)
|
528
|
+
assert expr2.include?((date2 + 12))
|
529
|
+
assert expr2.include?((date2 + 24))
|
530
|
+
end
|
531
|
+
|
532
|
+
def test_day_interval_te_to_s
|
533
|
+
every_four_days = DayIntervalTE.new(Date.new(2006,2,26), 4)
|
534
|
+
assert_equal "every 4th day after #{Runt.format_date(Date.new(2006,2,26))}", every_four_days.to_s
|
535
|
+
end
|
536
|
+
|
537
|
+
def test_year_te
|
538
|
+
# second sun of any month
|
539
|
+
second_sun = DIMonth.new(Second, Sunday)
|
540
|
+
# simple year matching expression which will return true for
|
541
|
+
# any date in 2005
|
542
|
+
year_te = YearTE.new(2005)
|
543
|
+
# Second Sunday of a month in 2002
|
544
|
+
dt_in_2002 = Date.civil(2002,9,8)
|
545
|
+
# Second Sunday of a month in 2005
|
546
|
+
dt_in_2005 = Date.civil(2005,12,11)
|
547
|
+
assert(year_te.include?(dt_in_2005))
|
548
|
+
assert(!year_te.include?(dt_in_2002))
|
549
|
+
end
|
550
|
+
|
551
|
+
def test_year_te
|
552
|
+
assert_equal 'during the year 1934', YearTE.new(1934).to_s
|
553
|
+
end
|
554
|
+
|
555
|
+
def test_use_time_class
|
556
|
+
monday=DIWeek.new(Mon) & REDay.new(9,30,17,30)
|
557
|
+
tues_to_fri=REWeek.new(Tue, Fri) & REDay.new(9,00,17,30)
|
558
|
+
exp=monday | tues_to_fri
|
559
|
+
assert(!exp.include?(Time.parse('Monday 06 November 2006 07:38')))
|
560
|
+
assert(exp.include?(Time.parse('Monday 06 November 2006 13:37')))
|
561
|
+
assert(exp.include?(Time.parse('Friday 10 November 2006 16:59')))
|
562
|
+
assert(!exp.include?(Time.parse('Friday 10 November 2006 17:31')))
|
563
|
+
end
|
564
|
+
|
565
|
+
def test_every_te_minutes
|
566
|
+
# Match every 2 minutes
|
567
|
+
xpr=EveryTE.new(PDate.min(2006,12,5,5,54), 2)
|
568
|
+
assert !xpr.include?(PDate.min(2006,12,4,5,54))
|
569
|
+
assert xpr.include?(PDate.min(2006,12,5,5,54))
|
570
|
+
assert xpr.include?(PDate.min(2006,12,5,5,56))
|
571
|
+
assert xpr.include?(PDate.sec(2006,12,5,5,58,03))
|
572
|
+
assert xpr.include?(PDate.min(2006,12,5,6,00))
|
573
|
+
assert !xpr.include?(PDate.min(2006,12,5,5,59))
|
574
|
+
assert xpr.include?(Time.parse('Tuesday 05 December 2006 07:08'))
|
575
|
+
# Match every 3 days
|
576
|
+
xpr2=EveryTE.new(PDate.day(2006,5,4), 3)
|
577
|
+
assert !xpr2.include?(Date.new(2006,5,5))
|
578
|
+
assert !xpr2.include?(PDate.new(2006,5,6))
|
579
|
+
assert xpr2.include?(PDate.new(2006,5,7))
|
580
|
+
assert xpr2.include?(PDate.min(2006,5,10,6,45))
|
581
|
+
end
|
582
|
+
|
583
|
+
def test_every_te_days
|
584
|
+
dstart = DateTime.parse("US-Eastern:19970902T090000")
|
585
|
+
dstart.date_precision = DPrecision::DAY
|
586
|
+
|
587
|
+
xpr=EveryTE.new(dstart, 10) & REWeek.new(Sun,Sat)
|
588
|
+
|
589
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970901T090000")) #Sep 1
|
590
|
+
assert xpr.include?(DateTime.parse("US-Eastern:19970902T090000")) #Sep 2
|
591
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970904T090000")) #Sep 3
|
592
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970904T090000")) #Sep 4
|
593
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970905T090000")) #Sep 5
|
594
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970906T090000")) #Sep 6
|
595
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970907T090000")) #Sep 7
|
596
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970908T090000")) #Sep 8
|
597
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970909T090000")) #Sep 9
|
598
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970910T090000")) #Sep 10
|
599
|
+
assert !xpr.include?(DateTime.parse("US-Eastern:19970911T090000")) #Sep 11
|
600
|
+
assert xpr.include?(DateTime.parse("US-Eastern:19970912T090000")) #Sep 12
|
601
|
+
assert xpr.include?(DateTime.parse("US-Eastern:19970922T090000")) #Sep 22
|
602
|
+
assert xpr.include?(DateTime.parse("US-Eastern:19971002T090000")) #Oct 2
|
603
|
+
assert xpr.include?(DateTime.parse("US-Eastern:19971012T090000")) #Oct 12
|
604
|
+
end
|
605
|
+
|
606
|
+
def test_every_te_to_s
|
607
|
+
date=PDate.new(2006,12,5,6,0,0)
|
608
|
+
every_thirty_seconds=EveryTE.new(date, 30)
|
609
|
+
assert_equal "every 30 seconds starting #{Runt.format_date(date)}", every_thirty_seconds.to_s
|
610
|
+
end
|
611
|
+
|
612
|
+
end
|