hiccup 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -72,6 +72,8 @@ module Hiccup
72
72
  end
73
73
 
74
74
  def n_occurrences_on_or_before(limit, date)
75
+ return nil if date < start_date
76
+
75
77
  occurrences = []
76
78
  enum = enumerator.new(self, date)
77
79
  while (occurrence = enum.prev) && occurrences.length < limit
@@ -1,3 +1,3 @@
1
1
  module Hiccup
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -61,11 +61,11 @@ class EnumerableTest < ActiveSupport::TestCase
61
61
  :start_date => Date.new(2009,3,15),
62
62
  :ends => true,
63
63
  :end_date => Date.new(2009,11,30)})
64
- dates = schedule.occurrences_during_month(2009,7).map {|date| date.day}
64
+ dates = occurrences_during_month(schedule, 2009,7).map {|date| date.day}
65
65
  expected_dates = [1,3,6,8,10,13,15,17,20,22,24,27,29,31]
66
66
  assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for weekly schedule"
67
67
 
68
- dates = schedule.occurrences_during_month(2008,7).map {|date| date.day}
68
+ dates = occurrences_during_month(schedule, 2008,7).map {|date| date.day}
69
69
  expected_dates = []
70
70
  assert_equal expected_dates, dates, "occurrences_during_month should generate no occurrences if before start_date"
71
71
 
@@ -75,7 +75,7 @@ class EnumerableTest < ActiveSupport::TestCase
75
75
  :start_date => Date.new(2010,6,14),
76
76
  :ends => true,
77
77
  :end_date => Date.new(2010,6,21)})
78
- dates = schedule.occurrences_during_month(2010,6).map {|date| date.day}
78
+ dates = occurrences_during_month(schedule, 2010,6).map {|date| date.day}
79
79
  expected_dates = [14,21]
80
80
  assert_equal expected_dates, dates, "occurrences_during_month did not correctly observe end date for weekly schedule"
81
81
  end
@@ -87,15 +87,15 @@ class EnumerableTest < ActiveSupport::TestCase
87
87
  :kind => :monthly,
88
88
  :monthly_pattern => [[2, "Sunday"], [4, "Sunday"]],
89
89
  :start_date => Date.new(2004,3,15)})
90
- dates = schedule.occurrences_during_month(2009,12).map {|date| date.day}
90
+ dates = occurrences_during_month(schedule, 2009,12).map {|date| date.day}
91
91
  expected_dates = [13,27]
92
92
  assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for monthly schedule"
93
93
 
94
- dates = schedule.occurrences_during_month(2009,2).map {|date| date.day}
94
+ dates = occurrences_during_month(schedule, 2009,2).map {|date| date.day}
95
95
  expected_dates = [8,22]
96
96
  assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for monthly schedule"
97
97
 
98
- dates = schedule.occurrences_during_month(1991,7).map {|date| date.day}
98
+ dates = occurrences_during_month(schedule, 1991,7).map {|date| date.day}
99
99
  expected_dates = []
100
100
  assert_equal expected_dates, dates, "occurrences_during_month should generate no occurrences if before start_date"
101
101
  end
@@ -198,6 +198,8 @@ class EnumerableTest < ActiveSupport::TestCase
198
198
  :end_date => Date.new(2011, 1, 31)})
199
199
  assert_equal nil, schedule.first_occurrence_before(Date.new(2011,1,3))
200
200
  assert_equal nil, schedule.first_occurrence_on_or_before(Date.new(2011,1,2))
201
+ assert_equal nil, schedule.n_occurrences_before(10, Date.new(2011,1,3))
202
+ assert_equal nil, schedule.n_occurrences_on_or_before(10, Date.new(2011,1,2))
201
203
  end
202
204
 
203
205
  test "should not predict dates after the end of a schedule" do
@@ -266,23 +268,23 @@ class EnumerableTest < ActiveSupport::TestCase
266
268
  schedule = Schedule.new({
267
269
  :kind => :annually,
268
270
  :start_date => Date.new(1981,4,23)})
269
- dates = schedule.occurrences_during_month(1981,4).map {|date| date.day}
271
+ dates = occurrences_during_month(schedule, 1981,4).map {|date| date.day}
270
272
  expected_dates = [23]
271
273
  assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for annual schedule"
272
274
 
273
- dates = schedule.occurrences_during_month(1972,4).map {|date| date.day}
275
+ dates = occurrences_during_month(schedule, 1972,4).map {|date| date.day}
274
276
  expected_dates = []
275
277
  assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for annual schedule"
276
278
 
277
- dates = schedule.occurrences_during_month(1984,4).map {|date| date.day}
279
+ dates = occurrences_during_month(schedule, 1984,4).map {|date| date.day}
278
280
  expected_dates = [23]
279
281
  assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for annual schedule"
280
282
 
281
- dates = schedule.occurrences_during_month(1984,3).map {|date| date.day}
283
+ dates = occurrences_during_month(schedule, 1984,3).map {|date| date.day}
282
284
  expected_dates = []
283
285
  assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for annual schedule"
284
286
 
285
- dates = schedule.occurrences_during_month(2009,12).map {|date| date.day}
287
+ dates = occurrences_during_month(schedule, 2009,12).map {|date| date.day}
286
288
  expected_dates = []
287
289
  assert_equal expected_dates, dates, "occurrences_during_month did not generate expected dates for annual schedule"
288
290
  end
@@ -297,7 +299,7 @@ class EnumerableTest < ActiveSupport::TestCase
297
299
 
298
300
  # There are not 5 Mondays during June 2010
299
301
  assert_nothing_raised do
300
- assert_equal [], schedule.occurrences_during_month(2010, 6)
302
+ assert_equal [], occurrences_during_month(schedule, 2010, 6)
301
303
  end
302
304
 
303
305
  next_fifth_month = Date.new(2010,8,30)
@@ -326,8 +328,8 @@ class EnumerableTest < ActiveSupport::TestCase
326
328
  :start_date => Date.new(2008, 2, 29)
327
329
  });
328
330
 
329
- assert_equal [Date.new(2010, 2, 28)], schedule.occurrences_during_month(2010, 2)
330
- assert_equal [Date.new(2012, 2, 29)], schedule.occurrences_during_month(2012, 2)
331
+ assert_equal [Date.new(2010, 2, 28)], occurrences_during_month(schedule, 2010, 2)
332
+ assert_equal [Date.new(2012, 2, 29)], occurrences_during_month(schedule, 2012, 2)
331
333
  end
332
334
 
333
335
 
@@ -339,8 +341,8 @@ class EnumerableTest < ActiveSupport::TestCase
339
341
  :start_date => Date.new(2008, 2, 29)
340
342
  })
341
343
 
342
- assert_equal [Date.new(2010, 1, 31)], schedule.occurrences_during_month(2010, 1)
343
- assert_equal [], schedule.occurrences_during_month(2010, 2)
344
+ assert_equal [Date.new(2010, 1, 31)], occurrences_during_month(schedule, 2010, 1)
345
+ assert_equal [], occurrences_during_month(schedule, 2010, 2)
344
346
  end
345
347
 
346
348
 
@@ -411,4 +413,16 @@ class EnumerableTest < ActiveSupport::TestCase
411
413
 
412
414
 
413
415
 
416
+ private
417
+
418
+
419
+
420
+ def occurrences_during_month(schedule, year, month)
421
+ date1 = Date.new(year, month, 1)
422
+ date2 = Date.new(year, month, -1)
423
+ schedule.occurrences_between(date1, date2)
424
+ end
425
+
426
+
427
+
414
428
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiccup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-21 00:00:00.000000000 Z
12
+ date: 2013-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -179,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
179
  version: '0'
180
180
  segments:
181
181
  - 0
182
- hash: -1495672392285233886
182
+ hash: -4462698178818777430
183
183
  required_rubygems_version: !ruby/object:Gem::Requirement
184
184
  none: false
185
185
  requirements:
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  version: '0'
189
189
  segments:
190
190
  - 0
191
- hash: -1495672392285233886
191
+ hash: -4462698178818777430
192
192
  requirements: []
193
193
  rubyforge_project: hiccup
194
194
  rubygems_version: 1.8.24