Skip to content

Commit

Permalink
Warn on DateTime input and convert to Time
Browse files Browse the repository at this point in the history
Fixes #144
  • Loading branch information
avit committed Feb 14, 2013
1 parent 2b8f9de commit 53d34b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
10 changes: 7 additions & 3 deletions lib/ice_cube/time_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ def self.match_zone(time, reference)
# Ensure that this is either nil, or a time
def self.ensure_time(time, date_eod = false)
case time
when DateTime then time.to_time
when Date then date_eod ? time.to_time.end_of_day : time.to_time
else time
when DateTime
warn "IceCube: DateTime support is deprecated (please use Time)"
time.to_time
when Date
date_eod ? end_of_date(time) : time.to_time
else
time
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/examples/rfc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
schedule.add_recurrence_rule IceCube::Rule.daily(2).until(Time.utc(1997, 12, 24))
dates = schedule.occurrences(Time.utc(1997, 12, 31))
offset = 0
(DateTime.civil(1997, 9, 2)..DateTime.civil(1997, 12, 24)).each do |date|
(Date.new(1997, 9, 2)..Date.new(1997, 12, 24)).each do |date|
dates.should include(Time.utc(date.year, date.month, date.day)) if offset % 2 == 0
dates.should_not include(Time.utc(date.year, date.month, date.day)) if offset % 2 != 0
offset += 1
Expand Down
24 changes: 16 additions & 8 deletions spec/examples/schedule_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
schedule.start_time.should == t1
end

it 'initializes with a start_time' do
t1 = Time.local(2013, 2, 14, 0, 32, 0)
schedule = IceCube::Schedule.new(t1)
schedule.start_time.should be_a Time
schedule.start_time.should == t1
end

it 'converts initialized DateTime to Time' do
dt = DateTime.new(2013, 2, 14, 0, 32, 0)
schedule = IceCube::Schedule.new(dt)
schedule.start_time.should be_a Time
schedule.start_time.should == dt.to_time
end

describe :duration do

it 'should be based on end_time' do
Expand Down Expand Up @@ -204,9 +218,8 @@
conflict.should be_true
end

it 'should return false if conflict is not present and single recurrence and time originally specified as DateTime' do
date = DateTime.new(2020,9,21,11,30,0)
start_time = date.to_time
it 'should return false if conflict is not present and single recurrence and time originally specified as Time' do
start_time = Time.new(2020,9,21,11,30,0)
schedule1 = IceCube::Schedule.new(start_time, :duration => IceCube::ONE_HOUR)
schedule1.add_recurrence_time(start_time)
schedule2 = IceCube::Schedule.new(start_time + IceCube::ONE_HOUR, :duration => IceCube::ONE_HOUR)
Expand Down Expand Up @@ -336,11 +349,6 @@
start_time = Time.utc(Time.now.year + 1, 7, 1, 0, 0, 0).localtime("-05:00")
compare_time_zone_info(start_time)
end

it 'should respect time zone info for a DateTime' do
start_time = DateTime.new(Time.now.year + 1, 7, 1, 0, 0, 0, "-05:00")
compare_time_zone_info(start_time)
end
end

describe :start_date= do
Expand Down

0 comments on commit 53d34b0

Please sign in to comment.