Class: PublicHoliday
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PublicHoliday
- Defined in:
- app/models/public_holiday.rb
Class Method Summary collapse
-
.find_by_week(year, week) ⇒ Object
Return an array of either a public holiday or nil for each day of the given week.
Class Method Details
.find_by_week(year, week) ⇒ Object
Return an array of either a public holiday or nil for each day of the given week.
3 4 5 6 7 8 9 10 11 |
# File 'app/models/public_holiday.rb', line 3 def self.find_by_week(year, week) first_date = Date.commercial(year, week, 1) last_date = first_date + 6 results = self.find(:all, :conditions => ['"on" BETWEEN ? AND ?', first_date, last_date], :order => '"on"') (0..6).each do |day| results.insert(day, nil) if results[day] && results[day].on > first_date + day end results end |