Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/models/teaching_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def date_for_week_and_day(week, day)

start_day_num = start_date.wday

result = week_start + (day_num - start_day_num).days
day_offset = day_num - start_day_num
day_offset += 7 if day_offset.negative?

result = week_start + day_offset.days

for a_break in breaks do
if result >= a_break.start_date && result < a_break.end_date
Expand Down
2 changes: 1 addition & 1 deletion test/models/teaching_period_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_create_teaching_period_with_invalid_dates
assert_equal tp.start_date + 3.day + 2.week, tp.date_for_week_and_day(3, 'Thu')
assert_equal tp.start_date + 4.day + 2.week, tp.date_for_week_and_day(3, 'Fri')
assert_equal tp.start_date + 5.day, tp.date_for_week_and_day(1, 'Sat')
assert_equal tp.start_date - 1.day, tp.date_for_week_and_day(1, 'Sun')
assert_equal tp.start_date + 6.days, tp.date_for_week_and_day(1, 'Sun')
end

test 'can map week and day to date after break' do
Expand Down
Loading