Permalink
Browse files

Removed an annoying error

Added some fixes for day_of_week (thanks again to mdotterer)
Issue 5 resolved
  • Loading branch information...
1 parent 18b9ac2 commit 485df2aaae9fbfa4fc7f248f81fae90c3c9add6c John Crepezzi committed Jun 25, 2010
Showing with 37 additions and 4 deletions.
  1. +3 −2 lib/ice_cube/validations/day_of_week.rb
  2. +34 −0 spec/examples/dst_spec.rb
  3. +0 −2 spec/examples/weekly_rule_spec.rb
@@ -21,8 +21,9 @@ def validate(date)
#note - temporary implementation
def closest(date)
return nil if !@days_of_week || @days_of_week.empty?
- while date += IceCube::ONE_DAY
- return date if validate(date)
+ goal = date
+ while goal += IceCube::ONE_DAY
+ return adjust(goal, date) if validate(goal)
end
end
@@ -217,5 +217,39 @@
schedule.first(3).should == [Time.local(2010, 3, 12, 19, 0, 0), Time.local(2012, 3, 12, 19, 0, 0), Time.local(2014, 3, 12, 19, 0, 0)]
end
+ it "local - should make dates on monthly (day of week) inverval over dst" do
+ start_date = Time.local(2010, 3, 7, 12, 0, 0)
+ schedule = Schedule.new(start_date)
+ schedule.add_recurrence_rule Rule.monthly.day_of_week(:sunday => [1])
+ schedule.first(3).should == [Time.local(2010, 3, 7, 12, 0, 0), Time.local(2010, 4, 4, 12, 0, 0), Time.local(2010, 5, 2, 12, 0, 0)]
+ end
+
+ it "local - should make dates on monthly (day of month) inverval over dst" do
+ start_date = Time.local(2010, 3, 1, 12, 0, 0)
+ schedule = Schedule.new(start_date)
+ schedule.add_recurrence_rule Rule.monthly.day_of_month(1)
+ schedule.first(3).should == [Time.local(2010, 3, 1, 12, 0, 0), Time.local(2010, 4, 1, 12, 0, 0), Time.local(2010, 5, 1, 12, 0, 0)]
+ end
+
+ it "local - should make dates on weekly (day) inverval over dst" do
+ start_date = Time.local(2010, 3, 7, 12, 0, 0)
+ schedule = Schedule.new(start_date)
+ schedule.add_recurrence_rule Rule.weekly.day(:sunday)
+ schedule.first(3).should == [Time.local(2010, 3, 7, 12, 0, 0), Time.local(2010, 3, 14, 12, 0, 0), Time.local(2010, 3, 21, 12, 0, 0)]
+ end
+
+ it "local - should make dates on monthly (day of year) inverval over dst" do
+ start_date = Time.local(2010, 3, 7, 12, 0, 0)
+ schedule = Schedule.new(start_date)
+ schedule.add_recurrence_rule Rule.monthly.day_of_year(1)
+ schedule.first(3).should == [Time.local(2011, 1, 1, 12, 0, 0), Time.local(2012, 1, 1, 12, 0, 0), Time.local(2013, 1, 1, 12, 0, 0)]
+ end
+
+ it "local - should make dates on monthly (month_of_year) inverval over dst" do
+ start_date = Time.local(2010, 3, 7, 12, 0, 0)
+ schedule = Schedule.new(start_date)
+ schedule.add_recurrence_rule Rule.yearly.month_of_year(:april).day_of_month(10)
+ schedule.first(3).should == [Time.local(2010, 4, 10, 12, 0, 0), Time.local(2011, 4, 10, 12, 0, 0), Time.local(2012, 4, 10, 12, 0, 0)]
+ end
end
@@ -2,8 +2,6 @@
describe WeeklyRule, 'occurs_on?' do
- WEDNESDAY = Time.utc(2010, 3, 10)
-
it 'should produce the correct number of days for @interval = 1 with no weekdays specified' do
start_date = Time.now
schedule = Schedule.new(start_date)

0 comments on commit 485df2a

Please sign in to comment.