hiccup 0.5.14 → 0.5.15
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.
- checksums.yaml +4 -4
- data/lib/hiccup.rb +17 -17
- data/lib/hiccup/convenience.rb +9 -9
- data/lib/hiccup/core_ext/date.rb +7 -7
- data/lib/hiccup/core_ext/duration.rb +4 -4
- data/lib/hiccup/core_ext/enumerable.rb +2 -2
- data/lib/hiccup/core_ext/fixnum.rb +2 -2
- data/lib/hiccup/core_ext/hash.rb +2 -2
- data/lib/hiccup/enumerable.rb +43 -29
- data/lib/hiccup/enumerable/annually_enumerator.rb +23 -23
- data/lib/hiccup/enumerable/monthly_date_enumerator.rb +2 -2
- data/lib/hiccup/enumerable/monthly_enumerator.rb +40 -40
- data/lib/hiccup/enumerable/never_enumerator.rb +8 -8
- data/lib/hiccup/enumerable/schedule_enumerator.rb +39 -39
- data/lib/hiccup/enumerable/weekly_enumerator.rb +30 -30
- data/lib/hiccup/errors.rb +4 -0
- data/lib/hiccup/humanizable.rb +19 -19
- data/lib/hiccup/inferable.rb +30 -30
- data/lib/hiccup/inferable/dates_enumerator.rb +6 -6
- data/lib/hiccup/inferable/guesser.rb +21 -21
- data/lib/hiccup/inferable/score.rb +7 -7
- data/lib/hiccup/inferable/scorer.rb +19 -19
- data/lib/hiccup/schedule.rb +10 -10
- data/lib/hiccup/serializable/ical.rb +13 -13
- data/lib/hiccup/serializers/ical.rb +59 -59
- data/lib/hiccup/validatable.rb +23 -23
- data/lib/hiccup/version.rb +1 -1
- data/test/core_ext_date_test.rb +5 -5
- data/test/duration_ext_test.rb +8 -8
- data/test/enumerable_test.rb +103 -103
- data/test/humanizable_test.rb +24 -24
- data/test/ical_serializable_test.rb +29 -29
- data/test/inferrable_test.rb +84 -84
- data/test/leap_year_test.rb +7 -7
- data/test/monthly_enumerator_test.rb +13 -13
- data/test/performance_test.rb +7 -7
- data/test/validatable_test.rb +1 -1
- data/test/weekly_enumerator_test.rb +38 -38
- metadata +4 -3
data/lib/hiccup/version.rb
CHANGED
data/test/core_ext_date_test.rb
CHANGED
@@ -2,8 +2,8 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
|
4
4
|
class CoreExtDateTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
|
7
7
|
test "should correctly identify the nth weekday of the month of a date" do
|
8
8
|
assert_equal 1, Date.new(2012, 7, 1).get_nth_wday_of_month
|
9
9
|
assert_equal 1, Date.new(2012, 7, 7).get_nth_wday_of_month
|
@@ -15,7 +15,7 @@ class CoreExtDateTest < ActiveSupport::TestCase
|
|
15
15
|
assert_equal 4, Date.new(2012, 7, 28).get_nth_wday_of_month
|
16
16
|
assert_equal 5, Date.new(2012, 7, 29).get_nth_wday_of_month
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
test "should correctly identify the nth weekday of the month of a date as a string" do
|
20
20
|
assert_equal "1 Sunday", Date.new(2012, 7, 1).get_nth_wday_string
|
21
21
|
assert_equal "1 Saturday", Date.new(2012, 7, 7).get_nth_wday_string
|
@@ -27,6 +27,6 @@ class CoreExtDateTest < ActiveSupport::TestCase
|
|
27
27
|
assert_equal "4 Saturday", Date.new(2012, 7, 28).get_nth_wday_string
|
28
28
|
assert_equal "5 Sunday", Date.new(2012, 7, 29).get_nth_wday_string
|
29
29
|
end
|
30
|
-
|
31
|
-
|
30
|
+
|
31
|
+
|
32
32
|
end
|
data/test/duration_ext_test.rb
CHANGED
@@ -3,27 +3,27 @@ require "hiccup/core_ext/duration"
|
|
3
3
|
|
4
4
|
|
5
5
|
class DurationExtTest < ActiveSupport::TestCase
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
|
8
8
|
def test_active_support_duration_is_working
|
9
9
|
assert 1.day.is_a?(ActiveSupport::Duration), "I ran into a problem where the Ruby gem 'god' also added :day to Fixnum and broke ActiveSupport."
|
10
10
|
end
|
11
|
-
|
12
|
-
|
11
|
+
|
12
|
+
|
13
13
|
def test_after_alias
|
14
14
|
t = 17.weeks.ago
|
15
15
|
[:day, :week, :month, :year].each do |period|
|
16
16
|
assert_equal 1.send(period).since(t), 1.send(period).after(t)
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
20
|
-
|
19
|
+
|
20
|
+
|
21
21
|
def test_before_alias
|
22
22
|
t = 17.weeks.ago
|
23
23
|
[:day, :week, :month, :year].each do |period|
|
24
24
|
assert_equal 1.send(period).ago(t), 1.send(period).before(t)
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
28
|
-
|
27
|
+
|
28
|
+
|
29
29
|
end
|
data/test/enumerable_test.rb
CHANGED
@@ -5,21 +5,21 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
5
5
|
include Hiccup
|
6
6
|
|
7
7
|
attr_reader :schedule
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
|
9
|
+
|
10
|
+
|
11
11
|
def test_occurs_on_annually
|
12
12
|
schedule = Schedule.new({
|
13
13
|
:kind => :annually,
|
14
14
|
:start_date => Date.new(2009,3,15)})
|
15
15
|
assert !schedule.occurs_on(Date.new(1984,3,15)), "Annual schedule starting 3/15/09 should not occur on 3/15/1984"
|
16
|
-
assert schedule.occurs_on(Date.new(2084,3,15)), "Annual schedule starting 3/15/09 should occur on 3/15/2084"
|
16
|
+
assert schedule.occurs_on(Date.new(2084,3,15)), "Annual schedule starting 3/15/09 should occur on 3/15/2084"
|
17
17
|
assert !schedule.occurs_on(Date.new(2011,4,15)), "Annual schedule starting 3/15/09 should not occur on 4/15/2011"
|
18
18
|
assert !schedule.occurs_on(Date.new(2009,3,17)), "Annual schedule starting 3/15/09 should not occur on 3/17/2009"
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
23
|
test "annual recurrence with a skip" do
|
24
24
|
schedule = Schedule.new({
|
25
25
|
:kind => :annually,
|
@@ -29,7 +29,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
29
29
|
actual_dates = schedule.occurrences_between(Date.new(2009, 01, 01), Date.new(2013, 12, 31)).map(&:to_s)
|
30
30
|
assert_equal expected_dates, actual_dates
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
test "annual recurrence with a skip, starting enumeration on an off year" do
|
34
34
|
schedule = Schedule.new({
|
35
35
|
:kind => :annually,
|
@@ -38,9 +38,9 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
38
38
|
assert_equal "2011-03-04", (schedule.first_occurrence_on_or_after Date.new(2010, 03, 01)).to_s
|
39
39
|
assert_equal "2011-03-04", (schedule.first_occurrence_on_or_before Date.new(2012, 03, 01)).to_s
|
40
40
|
end
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
|
42
|
+
|
43
|
+
|
44
44
|
def test_occurs_on_weekly
|
45
45
|
schedule = Schedule.new({
|
46
46
|
:kind => :weekly,
|
@@ -53,7 +53,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
53
53
|
assert schedule.occurs_on(Date.new(2009,3,16)), "MWF schedule starting 3/15/09 should occur on 3/16/2009"
|
54
54
|
assert !schedule.occurs_on(Date.new(2009,3,11)), "MWF schedule starting 3/15/09 should not occur on 3/11/2009"
|
55
55
|
assert schedule.occurs_on(Date.new(2009,3,18)), "MWF schedule starting 3/15/09 should occur on 3/18/2009"
|
56
|
-
|
56
|
+
|
57
57
|
schedule.end_date = Date.new(2009,4,11)
|
58
58
|
schedule.ends = true
|
59
59
|
assert_equal true, schedule.ends?
|
@@ -61,9 +61,9 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
61
61
|
assert !schedule.occurs_on(Date.new(2009,5,11)), "MWF schedule starting 3/15/09 and ending 4/11/09 should not occur on 5/11/2009"
|
62
62
|
assert !schedule.occurs_on(Date.new(2009,5,20)), "MWF schedule starting 3/15/09 and ending 4/11/09 should not occur on 5/20/2009"
|
63
63
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
|
65
|
+
|
66
|
+
|
67
67
|
def test_weekly_occurrences_during_month
|
68
68
|
schedule = Schedule.new({
|
69
69
|
:kind => :weekly,
|
@@ -74,11 +74,11 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
74
74
|
dates = occurrences_during_month(schedule, 2009,7).map {|date| date.day}
|
75
75
|
expected_dates = [1,3,6,8,10,13,15,17,20,22,24,27,29,31]
|
76
76
|
assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for weekly schedule"
|
77
|
-
|
77
|
+
|
78
78
|
dates = occurrences_during_month(schedule, 2008,7).map {|date| date.day}
|
79
79
|
expected_dates = []
|
80
80
|
assert_equal expected_dates, dates, "occurrences_during_month should generate no occurrences if before start_date"
|
81
|
-
|
81
|
+
|
82
82
|
schedule = Schedule.new({
|
83
83
|
:kind => :weekly,
|
84
84
|
:weekly_pattern => %w{Monday},
|
@@ -89,20 +89,20 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
89
89
|
expected_dates = [14,21]
|
90
90
|
assert_equal expected_dates, dates, "occurrences_during_month did not correctly observe end date for weekly schedule"
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
test "should keep weekly occurrences during a week together when skipping" do
|
94
94
|
schedule = Schedule.new(
|
95
95
|
:kind => :weekly,
|
96
96
|
:weekly_pattern => %w{Tuesday Thursday},
|
97
97
|
:start_date => Date.new(2013, 10, 2), # Wednesday
|
98
98
|
:skip => 2)
|
99
|
-
|
99
|
+
|
100
100
|
dates = occurrences_during_month(schedule, 2013, 10).map(&:day)
|
101
101
|
assert_equal [3, 15, 17, 29, 31], dates
|
102
102
|
end
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
|
104
|
+
|
105
|
+
|
106
106
|
def test_monthly_occurrences_during_month
|
107
107
|
schedule = Schedule.new({
|
108
108
|
:kind => :monthly,
|
@@ -111,18 +111,18 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
111
111
|
dates = occurrences_during_month(schedule, 2009,12).map {|date| date.day}
|
112
112
|
expected_dates = [13,27]
|
113
113
|
assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for monthly schedule"
|
114
|
-
|
114
|
+
|
115
115
|
dates = occurrences_during_month(schedule, 2009,2).map {|date| date.day}
|
116
116
|
expected_dates = [8,22]
|
117
117
|
assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for monthly schedule"
|
118
|
-
|
118
|
+
|
119
119
|
dates = occurrences_during_month(schedule, 1991,7).map {|date| date.day}
|
120
120
|
expected_dates = []
|
121
121
|
assert_equal expected_dates, dates, "occurrences_during_month should generate no occurrences if before start_date"
|
122
122
|
end
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
|
124
|
+
|
125
|
+
|
126
126
|
def test_no_occurrence
|
127
127
|
expected_date = Date.new(2011,3,12)
|
128
128
|
schedule = Schedule.new({:kind => :never, :start_date => expected_date})
|
@@ -130,9 +130,9 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
130
130
|
assert_equal expected_dates, schedule.occurrences_between(Date.new(2011,1,1), Date.new(2011,12,31))
|
131
131
|
assert schedule.contains?(expected_date)
|
132
132
|
end
|
133
|
-
|
134
133
|
|
135
|
-
|
134
|
+
|
135
|
+
|
136
136
|
context "#n_occurrences_before" do
|
137
137
|
setup do
|
138
138
|
@schedule = Schedule.new({
|
@@ -151,10 +151,10 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
151
151
|
"2009-10-09" ]
|
152
152
|
assert_equal expected_dates, dates, "Expected the dates for the correct occurrences"
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
should "return a shorter array if no events exist before the given date" do
|
156
156
|
dates = schedule.n_occurrences_before(10, Date.new(2009, 3, 20)).map { |date| date.strftime("%Y-%m-%d") }
|
157
|
-
|
157
|
+
|
158
158
|
expected_dates = ["2009-03-18", "2009-03-16"]
|
159
159
|
assert_equal expected_dates, dates, "Expected the dates for the correct occurrences"
|
160
160
|
end
|
@@ -204,9 +204,9 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
204
204
|
end
|
205
205
|
end
|
206
206
|
end
|
207
|
-
|
208
|
-
|
209
|
-
|
207
|
+
|
208
|
+
|
209
|
+
|
210
210
|
def test_how_contains_handles_parameter_types
|
211
211
|
date = Date.new(1981,4,23)
|
212
212
|
schedule = Schedule.new({:kind => :annually, :start_date => date})
|
@@ -214,9 +214,9 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
214
214
|
assert schedule.contains?(date.to_time)
|
215
215
|
assert schedule.contains?(date.to_datetime)
|
216
216
|
end
|
217
|
-
|
218
|
-
|
219
|
-
|
217
|
+
|
218
|
+
|
219
|
+
|
220
220
|
def test_monthly_occurrences
|
221
221
|
occurrence = [1, "Wednesday"]
|
222
222
|
schedule = Schedule.new({
|
@@ -226,15 +226,15 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
226
226
|
expected_dates = [[1,5], [2,2], [3,2], [4,6], [5,4], [6,1], [7,6], [8,3], [9,7], [10,5], [11,2], [12,7]]
|
227
227
|
expected_dates.map! {|pair| Date.new(2011, *pair)}
|
228
228
|
assert_equal expected_dates, schedule.occurrences_between(Date.new(2011,1,1), Date.new(2011,12,31))
|
229
|
-
|
229
|
+
|
230
230
|
(0...(expected_dates.length - 1)).each do |i|
|
231
231
|
assert_equal expected_dates[i+1], schedule.next_occurrence_after(expected_dates[i])
|
232
232
|
assert_equal expected_dates[i], schedule.first_occurrence_before(expected_dates[i + 1])
|
233
233
|
end
|
234
234
|
end
|
235
|
-
|
236
|
-
|
237
|
-
|
235
|
+
|
236
|
+
|
237
|
+
|
238
238
|
test "should not throw an exception when calculating monthly recurrence and skip causes a guess to be discarded" do
|
239
239
|
schedule = Schedule.new({
|
240
240
|
:kind => :monthly,
|
@@ -250,9 +250,9 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
250
250
|
:end_date => Date.new(2012,3,29)})
|
251
251
|
schedule.occurrences_between(schedule.start_date, schedule.end_date)
|
252
252
|
end
|
253
|
-
|
254
|
-
|
255
|
-
|
253
|
+
|
254
|
+
|
255
|
+
|
256
256
|
test "should not predict dates before the beginning of a schedule" do
|
257
257
|
schedule = Schedule.new({
|
258
258
|
:kind => :weekly,
|
@@ -265,7 +265,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
265
265
|
assert_equal [], schedule.n_occurrences_before(10, Date.new(2011,1,3))
|
266
266
|
assert_equal [], schedule.n_occurrences_on_or_before(10, Date.new(2011,1,2))
|
267
267
|
end
|
268
|
-
|
268
|
+
|
269
269
|
test "should predict nonrecurring dates before a date later than them" do
|
270
270
|
schedule = Schedule.new({
|
271
271
|
:kind => :never,
|
@@ -273,7 +273,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
273
273
|
assert_equal [Date.new(2011, 1, 3)], schedule.n_occurrences_on_or_before(10, Date.new(2011,1,3))
|
274
274
|
assert_equal [], schedule.n_occurrences_on_or_before(10, Date.new(2011,1,2))
|
275
275
|
end
|
276
|
-
|
276
|
+
|
277
277
|
test "should not predict dates after the end of a schedule" do
|
278
278
|
schedule = Schedule.new({
|
279
279
|
:kind => :weekly,
|
@@ -285,9 +285,9 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
285
285
|
assert_equal nil, schedule.first_occurrence_on_or_after(Date.new(2011,2, 1))
|
286
286
|
assert_equal [], schedule.occurrences_between(Date.new(2013, 9, 23), Date.new(2013, 9, 30))
|
287
287
|
end
|
288
|
-
|
289
|
-
|
290
|
-
|
288
|
+
|
289
|
+
|
290
|
+
|
291
291
|
test "all methods should take any kind of date as an argument" do
|
292
292
|
schedule = Schedule.new({
|
293
293
|
:kind => :weekly,
|
@@ -298,9 +298,9 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
298
298
|
assert_equal Date.new(2011, 1, 17), schedule.first_occurrence_after(Time.new(2011, 1, 10))
|
299
299
|
assert_equal Date.new(2011, 1, 3), schedule.first_occurrence_before(Time.new(2011, 1, 10))
|
300
300
|
end
|
301
|
-
|
302
|
-
|
303
|
-
|
301
|
+
|
302
|
+
|
303
|
+
|
304
304
|
def test_weekly_recurrence_and_skip
|
305
305
|
schedule = Schedule.new({
|
306
306
|
:kind => :weekly,
|
@@ -310,15 +310,15 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
310
310
|
expected_dates = [[1,3], [1,24], [2,14], [3,7], [3,28]]
|
311
311
|
expected_dates.map! {|pair| Date.new(2011, *pair)}
|
312
312
|
assert_equal expected_dates, schedule.occurrences_between(Date.new(2011,1,1), Date.new(2011,3,31))
|
313
|
-
|
313
|
+
|
314
314
|
(0...(expected_dates.length - 1)).each do |i|
|
315
315
|
assert_equal expected_dates[i+1], schedule.next_occurrence_after(expected_dates[i])
|
316
316
|
assert_equal expected_dates[i], schedule.first_occurrence_before(expected_dates[i + 1])
|
317
317
|
end
|
318
318
|
end
|
319
|
-
|
320
|
-
|
321
|
-
|
319
|
+
|
320
|
+
|
321
|
+
|
322
322
|
def test_monthly_recurrence_and_skip
|
323
323
|
schedule = Schedule.new({
|
324
324
|
:kind => :monthly,
|
@@ -328,15 +328,15 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
328
328
|
expected_dates = [[1,5], [3,2], [5,4], [7,6], [9,7], [11,2]]
|
329
329
|
expected_dates.map! {|pair| Date.new(2011, *pair)}
|
330
330
|
assert_equal expected_dates, schedule.occurrences_between(Date.new(2011,1,1), Date.new(2011,12,31))
|
331
|
-
|
331
|
+
|
332
332
|
(0...(expected_dates.length - 1)).each do |i|
|
333
333
|
assert_equal expected_dates[i+1], schedule.next_occurrence_after(expected_dates[i])
|
334
334
|
assert_equal expected_dates[i], schedule.first_occurrence_before(expected_dates[i + 1])
|
335
335
|
end
|
336
336
|
end
|
337
|
-
|
338
|
-
|
339
|
-
|
337
|
+
|
338
|
+
|
339
|
+
|
340
340
|
def test_annual_occurrences_during_month
|
341
341
|
schedule = Schedule.new({
|
342
342
|
:kind => :annually,
|
@@ -344,11 +344,11 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
344
344
|
dates = occurrences_during_month(schedule, 1981,4).map {|date| date.day}
|
345
345
|
expected_dates = [23]
|
346
346
|
assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for annual schedule"
|
347
|
-
|
347
|
+
|
348
348
|
dates = occurrences_during_month(schedule, 1972,4).map {|date| date.day}
|
349
349
|
expected_dates = []
|
350
350
|
assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for annual schedule"
|
351
|
-
|
351
|
+
|
352
352
|
dates = occurrences_during_month(schedule, 1984,4).map {|date| date.day}
|
353
353
|
expected_dates = [23]
|
354
354
|
assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for annual schedule"
|
@@ -361,7 +361,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
361
361
|
expected_dates = []
|
362
362
|
assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for annual schedule"
|
363
363
|
end
|
364
|
-
|
364
|
+
|
365
365
|
test "When there is no 5th weekday of a month, schedule shouldn't crash" do
|
366
366
|
start = Date.new(2010,6,1)
|
367
367
|
schedule = Schedule.new({
|
@@ -369,18 +369,18 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
369
369
|
:monthly_pattern => [[5, "Monday"]],
|
370
370
|
:start_date => start})
|
371
371
|
assert_equal "The fifth Monday of every month", schedule.humanize
|
372
|
-
|
372
|
+
|
373
373
|
# There are not 5 Mondays during June 2010
|
374
374
|
assert_nothing_raised do
|
375
375
|
assert_equal [], occurrences_during_month(schedule, 2010, 6)
|
376
376
|
end
|
377
|
-
|
377
|
+
|
378
378
|
next_fifth_month = Date.new(2010,8,30)
|
379
379
|
assert_equal next_fifth_month, schedule.first_occurrence_on_or_after(start)
|
380
380
|
end
|
381
|
-
|
382
|
-
|
383
|
-
|
381
|
+
|
382
|
+
|
383
|
+
|
384
384
|
def test_first_occurrence_on_or_after
|
385
385
|
fifth_sunday = Date.new(2010, 8, 29)
|
386
386
|
schedule = Schedule.new({
|
@@ -388,38 +388,38 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
388
388
|
:monthly_pattern => [[5, "Sunday"]],
|
389
389
|
:start_date => fifth_sunday})
|
390
390
|
assert_equal "The fifth Sunday of every month", schedule.humanize
|
391
|
-
|
391
|
+
|
392
392
|
assert_equal fifth_sunday, schedule.first_occurrence_on_or_after(fifth_sunday)
|
393
393
|
assert schedule.contains?(fifth_sunday)
|
394
394
|
end
|
395
|
-
|
396
|
-
|
397
|
-
|
395
|
+
|
396
|
+
|
397
|
+
|
398
398
|
def test_february_29
|
399
399
|
schedule = Schedule.new({
|
400
400
|
:kind => :annually,
|
401
401
|
:start_date => Date.new(2008, 2, 29)
|
402
402
|
});
|
403
|
-
|
403
|
+
|
404
404
|
assert_equal [Date.new(2010, 2, 28)], occurrences_during_month(schedule, 2010, 2)
|
405
405
|
assert_equal [Date.new(2012, 2, 29)], occurrences_during_month(schedule, 2012, 2)
|
406
406
|
end
|
407
|
-
|
408
|
-
|
409
|
-
|
407
|
+
|
408
|
+
|
409
|
+
|
410
410
|
def test_recurs_on31st
|
411
411
|
schedule = Schedule.new({
|
412
412
|
:kind => :monthly,
|
413
413
|
:monthly_pattern => [31],
|
414
414
|
:start_date => Date.new(2008, 2, 29)
|
415
415
|
})
|
416
|
-
|
416
|
+
|
417
417
|
assert_equal [Date.new(2010, 1, 31)], occurrences_during_month(schedule, 2010, 1)
|
418
418
|
assert_equal [], occurrences_during_month(schedule, 2010, 2)
|
419
419
|
end
|
420
|
-
|
421
|
-
|
422
|
-
|
420
|
+
|
421
|
+
|
422
|
+
|
423
423
|
context "when a weekly schedule includes October 1582" do
|
424
424
|
setup do
|
425
425
|
@schedule = Schedule.new(
|
@@ -427,12 +427,12 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
427
427
|
weekly_pattern: %w{Monday},
|
428
428
|
start_date: Date.new(1582, 10, 1))
|
429
429
|
end
|
430
|
-
|
430
|
+
|
431
431
|
should "just skip the invalid dates" do
|
432
432
|
assert_equal %w{10/01 10/18 10/25}, occurrences_during_month(@schedule, 1582, 10).map { |d| d.strftime("%m/%d") }
|
433
433
|
end
|
434
434
|
end
|
435
|
-
|
435
|
+
|
436
436
|
context "when a monthly schedule includes October 1582" do
|
437
437
|
setup do
|
438
438
|
@schedule = Schedule.new(
|
@@ -440,35 +440,35 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
440
440
|
monthly_pattern: [5, 19],
|
441
441
|
start_date: Date.new(1582, 9, 5))
|
442
442
|
end
|
443
|
-
|
443
|
+
|
444
444
|
should "just skip the invalid dates" do
|
445
445
|
assert_equal %w{10/19}, occurrences_during_month(@schedule, 1582, 10).map { |d| d.strftime("%m/%d") }
|
446
446
|
end
|
447
447
|
end
|
448
|
-
|
448
|
+
|
449
449
|
context "when a yearly schedule includes October 1582" do
|
450
450
|
setup do
|
451
451
|
@schedule = Schedule.new(
|
452
452
|
kind: :annually,
|
453
453
|
start_date: Date.new(1580, 10, 8))
|
454
454
|
end
|
455
|
-
|
455
|
+
|
456
456
|
should "just skip the invalid dates" do
|
457
457
|
assert_equal [], occurrences_during_month(@schedule, 1582, 10).map { |d| d.strftime("%m/%d") }
|
458
458
|
end
|
459
459
|
end
|
460
|
-
|
461
|
-
|
462
|
-
|
460
|
+
|
461
|
+
|
462
|
+
|
463
463
|
if ENV['PERFORMANCE_TEST']
|
464
464
|
test "performance test" do
|
465
465
|
n = 1000
|
466
|
-
|
466
|
+
|
467
467
|
# Each of these schedules should describe 52 events
|
468
|
-
|
468
|
+
|
469
469
|
Benchmark.bm(20) do |x|
|
470
470
|
x.report("weekly (simple):") do
|
471
|
-
n.times do
|
471
|
+
n.times do
|
472
472
|
Schedule.new(
|
473
473
|
:kind => :weekly,
|
474
474
|
:weekly_pattern => ["Friday"],
|
@@ -477,7 +477,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
477
477
|
end
|
478
478
|
end
|
479
479
|
x.report("weekly (complex):") do
|
480
|
-
n.times do
|
480
|
+
n.times do
|
481
481
|
Schedule.new(
|
482
482
|
:kind => :weekly,
|
483
483
|
:weekly_pattern => ["Monday", "Wednesday", "Friday"],
|
@@ -520,22 +520,22 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
520
520
|
end
|
521
521
|
end
|
522
522
|
end
|
523
|
-
|
523
|
+
|
524
524
|
end
|
525
525
|
end
|
526
|
-
|
527
|
-
|
528
|
-
|
526
|
+
|
527
|
+
|
528
|
+
|
529
529
|
private
|
530
|
-
|
531
|
-
|
532
|
-
|
530
|
+
|
531
|
+
|
532
|
+
|
533
533
|
def occurrences_during_month(schedule, year, month)
|
534
534
|
date1 = Date.new(year, month, 1)
|
535
535
|
date2 = Date.new(year, month, -1)
|
536
536
|
schedule.occurrences_between(date1, date2)
|
537
537
|
end
|
538
|
-
|
539
|
-
|
540
|
-
|
538
|
+
|
539
|
+
|
540
|
+
|
541
541
|
end
|