Commit 8289f62f authored by Sean Arnold's avatar Sean Arnold

Move end date calculation to ActivePeriod class

- Minor spec tidy up
parent 9fc605a3
...@@ -11,7 +11,9 @@ module IncidentManagement ...@@ -11,7 +11,9 @@ module IncidentManagement
end_time > start_time if present? end_time > start_time if present?
end end
def for_dates(start_date, end_date) def for_date(start_date)
end_date = end_after_start? ? start_date : start_date.next_day
[ [
start_date.change(hour: start_time.hour, min: start_time.min), start_date.change(hour: start_time.hour, min: start_time.min),
end_date.change(hour: end_time.hour, min: end_time.min) end_date.change(hour: end_time.hour, min: end_time.min)
......
...@@ -129,10 +129,8 @@ module IncidentManagement ...@@ -129,10 +129,8 @@ module IncidentManagement
# expected_shift_count = 14 -> pretend it's a 2-week rotation # expected_shift_count = 14 -> pretend it's a 2-week rotation
# shift_count = 2 -> we're calculating the shift for the 3rd day # shift_count = 2 -> we're calculating the shift for the 3rd day
# starts_at = Monday 00:00:00 + 8.hours + 2.days => Thursday 08:00:00 # starts_at = Monday 00:00:00 + 8.hours + 2.days => Thursday 08:00:00
start_date = end_date = shift_cycle_starts_at + shift_count.days start_date = shift_cycle_starts_at + shift_count.days
end_date = start_date + 1.day unless rotation.active_period.end_after_start? starts_at, ends_at = rotation.active_period.for_date(start_date)
starts_at, ends_at = rotation.active_period.for_dates(start_date, end_date)
shift_for(participant, [rotation.starts_at, starts_at].max, limit_end_time(ends_at)) shift_for(participant, [rotation.starts_at, starts_at].max, limit_end_time(ends_at))
end end
......
...@@ -10,7 +10,7 @@ RSpec.describe API::Issues, :mailer do ...@@ -10,7 +10,7 @@ RSpec.describe API::Issues, :mailer do
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:epic) { create(:epic, group: group) } let_it_be(:epic) { create(:epic, group: group) }
let_it_be(:group_project) { create( :project, :public, creator_id: user.id, namespace: group) } let_it_be(:group_project) { create(:project, :public, creator_id: user.id, namespace: group) }
let(:user2) { create(:user) } let(:user2) { create(:user) }
......
...@@ -4,6 +4,6 @@ module OncallHelpers ...@@ -4,6 +4,6 @@ module OncallHelpers
def active_period_for_date_with_tz(date, rotation) def active_period_for_date_with_tz(date, rotation)
date = date.in_time_zone(rotation.schedule.timezone) date = date.in_time_zone(rotation.schedule.timezone)
rotation.active_period.for_dates(date, date) rotation.active_period.for_date(date)
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment