Skip to content

Commit

Permalink
Merge branch 'master' into issue103
Browse files Browse the repository at this point in the history
Conflicts:
	lib/ice_cube/validations/until.rb
  • Loading branch information
seejohnrun committed Oct 28, 2012
2 parents 7de4837 + bda9c5b commit 00dc669
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 9 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG
Expand Up @@ -82,8 +82,6 @@

0.8.1

----

0.9.0
* Fix the affect on end_time on IceCube::Schedule [#99]
* Remove end_time from `to_s` [#99]
Expand All @@ -94,3 +92,12 @@
* Ignore usecs when creating Time.now for *_occurrences [#84]
* DST bug fix [#98]
* Added occurring_between? [#88]

0.9.1
* A fix for removing until validations [#106]
* A DST edge fix

---

0.9.2
* Allow passing Time, Date, or DateTime to all calls
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -2,6 +2,10 @@

[![Build Status](https://secure.travis-ci.org/seejohnrun/ice_cube.png)](http://travis-ci.org/seejohnrun/ice_cube)

<a href="https://www.stripeme.com/pay/1lq0">
<img alt="Pay" src="https://www.stripeme.com/pay.jpg" />
</a>

``` bash
gem install ice_cube
```
Expand Down
9 changes: 7 additions & 2 deletions lib/ice_cube/validated_rule.rb
Expand Up @@ -39,9 +39,14 @@ def next_time(time, schedule, closing_time)
wrapper = TimeUtil::TimeWrapper.new(time, dst_adjust)
wrapper.add(type, fwd)
wrapper.clear_below(type)
if wrapper.to_time == time
wrapper.add(:sec, wrapper.to_time.utc_offset * 2)
# Move over DST if blocked, no adjustments
if wrapper.to_time <= time
wrapper = TimeUtil::TimeWrapper.new(wrapper.to_time, false)
until wrapper.to_time > time
wrapper.add(:min, 10) # smallest interval
end
end
# And then get the correct time out
time = wrapper.to_time
end
false
Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/validations/until.rb
Expand Up @@ -12,7 +12,7 @@ def until_time

def until(time)
@until = TimeUtil.ensure_time time
replace_validations_for(:until, [Validation.new(time)])
replace_validations_for(:until, time.nil? ? nil : [Validation.new(time)])
self
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ice_cube/version.rb
@@ -1,5 +1,5 @@
module IceCube

VERSION = '0.9.0'
VERSION = '0.9.1'

end
4 changes: 2 additions & 2 deletions spec/examples/ice_cube_spec.rb
Expand Up @@ -54,7 +54,7 @@
end

it 'should be able to exclude a certain date from a range' do
start_date = Time.now
start_date = Time.local 2012, 3, 1
schedule = IceCube::Schedule.new(start_date)
schedule.add_recurrence_rule IceCube::Rule.daily
schedule.add_exception_date(start_date + 1 * IceCube::ONE_DAY) # all days except tomorrow
Expand Down Expand Up @@ -808,7 +808,7 @@
rule = IceCube::Rule.daily.until(Time.now + IceCube::ONE_DAY)
rule.to_hash[:until].should_not be_nil
rule.until nil
rule.to_hash[:until].should be_nil
rule.to_hash.should_not have_key(:until)
end

# Full required for rules account for @interval
Expand Down
31 changes: 30 additions & 1 deletion spec/examples/regression_spec.rb
Expand Up @@ -114,7 +114,7 @@
it 'should return true if a recurring schedule occurs_between? a time range [#88]' do
start_time = Time.new(2012, 7, 7, 8)
schedule = IceCube::Schedule.new(start_time, :duration => 2 * IceCube::ONE_HOUR)
schedule.add_recurrence_rule Rule.weekly
schedule.add_recurrence_rule IceCube::Rule.weekly
t1 = Time.new(2012, 7, 14, 9)
t2 = Time.new(2012, 7, 14, 11)
schedule.occurring_between?(t1, t2).should be_true
Expand Down Expand Up @@ -159,6 +159,14 @@
occ.detect { |o| o.year == 2013 && o.month == 3 && o.day == 31 }.should be_true
end

it "failing spec for hanging on DST boundary [#98]" do
Time.zone = "Europe/London"
first = Time.zone.parse("Sun, 31 Mar 2013 00:00:00 GMT +00:00")
schedule = IceCube::Schedule.new(first)
schedule.add_recurrence_rule IceCube::Rule.monthly
next_occurance = schedule.next_occurrence(first)
end

it 'should exclude a date from a weekly schedule - issue #55' do
Time.zone = 'Eastern Time (US & Canada)'
ex = Time.zone.local(2011, 12, 27, 14)
Expand All @@ -169,4 +177,25 @@
schedule.first.should == Time.zone.local(2011, 12, 29, 14)
end

it 'should not raise an exception after setting the rule until to nil' do
rule = IceCube::Rule.daily.until(Time.local(2012, 10, 1))
rule.until(nil)

schedule = IceCube::Schedule.new Time.local(2011, 10, 11, 12)
schedule.add_recurrence_rule rule

lambda {
schedule.occurrences_between(Time.local(2012, 1, 1), Time.local(2012, 12, 1))
}.should_not raise_error(ArgumentError, 'comparison of Time with nil failed')
end

it 'should not infinite loop [#109]' do
schedule = IceCube::Schedule.new Time.new(2012, 4, 27, 0, 0, 0)
schedule.rrule IceCube::Rule.weekly.day(:monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday).hour_of_day(0).minute_of_hour(0).second_of_minute(0)
schedule.duration = 3600
start_time = Time.new(2012, 10, 20, 0, 0, 0)
end_time = Time.new(2012, 10, 20, 23, 59, 59)
schedule.occurrences_between(start_time, end_time).first.should == start_time
end

end
42 changes: 42 additions & 0 deletions spec/examples/validated_rule_spec.rb
@@ -0,0 +1,42 @@
require 'active_support/time'
require File.dirname(__FILE__) + '/../spec_helper'

describe IceCube, "::ValidatedRule" do
describe "#next_time" do
context "monthly" do
let(:rule) { IceCube::Rule.monthly }
before { rule.reset }
it "Should return current day when starting on same day" do
first = Time.new(2013, 2, 25, 0, 0, 0)
schedule = IceCube::Schedule.new(first)
schedule.add_recurrence_rule rule
rule.next_time(first, schedule, nil).should == first
end

it "Should return the next month when starting one second in the future" do
first = Time.new(2013, 2, 25, 0, 0, 0)
schedule = IceCube::Schedule.new(first)
schedule.add_recurrence_rule rule
rule.next_time(first + 1, schedule, nil).should == Time.new(2013, 3, 25, 0, 0, 0)
end

context "DST edge" do
before { Time.zone = "Europe/London" }
let(:first) { Time.zone.parse("Sun, 31 Mar 2013 00:00:00 GMT +00:00") }
let(:schedule) {
sc = IceCube::Schedule.new(first)
sc.add_recurrence_rule rule
sc
}

it "should not return the same time on a DST edge when starting one second in the future (results in infinite loop [#98])" do
rule.next_time(first + 1, schedule, nil).to_s.should_not == first.to_s
end

it "previous failing test with DST edge taken into account" do
rule.next_time(first + 1.hour + 1.second, schedule, nil).to_s.should_not == first.to_s
end
end
end
end
end

0 comments on commit 00dc669

Please sign in to comment.