Skip to content

Commit ce8d29b

Browse files
committed
fix: query holidays by term date range instead of term_id
Holidays that fall between semesters (winter break, spring break, etc.) have no term_id because they fall outside any term's start_date..end_date window. Filtering by term_id excluded them entirely. Now we query all holidays within the date range spanned by the user's enrolled terms.
1 parent 9712616 commit ce8d29b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

app/controllers/calendars_controller.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,13 @@ def add_university_events(cal)
182182
enrolled_term_ids = @courses.map(&:term_id).compact.uniq
183183
return if enrolled_term_ids.empty?
184184

185-
UniversityCalendarEvent.holidays.where(term_id: enrolled_term_ids).find_each do |event|
186-
add_university_event_to_calendar(cal, event, force_all_day: true)
185+
terms = Term.where(id: enrolled_term_ids).where.not(start_date: nil).where.not(end_date: nil)
186+
if terms.any?
187+
min_date = terms.minimum(:start_date)
188+
max_date = terms.maximum(:end_date)
189+
UniversityCalendarEvent.holidays.in_date_range(min_date, max_date).find_each do |event|
190+
add_university_event_to_calendar(cal, event, force_all_day: true)
191+
end
187192
end
188193

189194
user_config = @user.user_extension_config

0 commit comments

Comments
 (0)