Fix failing calendar generator tests

pull/323/head
Rick Carlino 2017-04-17 09:58:13 -05:00
parent ec63dd5be2
commit 4a7740fb1c
2 changed files with 14 additions and 9 deletions

View File

@ -27,12 +27,17 @@ module FarmEvents
return []
else
one_interval = (repeat * TIME[time_unit]).seconds
next_year = Time.now + 1.year
return [*(0..59)].map { |i|
t = (start_time + (i * one_interval))
expired = (t > (end_time || t)) || (t < Time.now)
# Seeing dates more than 1 year out is confusing.
too_far_ahead = t > (Time.now + 1.year)
(expired || too_far_ahead) ? nil : t
too_far_off = t > next_year
already_past = Time.now > t
beyond_end_time = t > (end_time || t)
valid = !(already_past || beyond_end_time || too_far_off)
(valid ? t : nil)
}.compact
end
end

View File

@ -28,14 +28,14 @@ describe FarmEvents::GenerateCalendar do
end
it 'has a known calendar bug' do
pending
tomorrow = Time.now + 1.day
calendar = FarmEvents::GenerateCalendar.run!(
"start_time" => "2017-04-10T15:00:00.000Z",
"end_time" => "2017-04-11T01:00:00.000Z",
"repeat" => 1,
"time_unit" => "minutely")
"start_time" => tomorrow,
"end_time" => tomorrow + 10.hours,
"repeat" => 2,
"time_unit" => "hourly")
expect(calendar.length).to be > 3
expect(calendar.length).to be < 7
# binding.pry
end
end