diff options
author | Matthew Landauer <matthew@openaustralia.org> | 2012-09-24 13:17:16 +1000 |
---|---|---|
committer | Matthew Landauer <matthew@openaustralia.org> | 2012-09-24 13:17:16 +1000 |
commit | c0b90c478a6fd17fd0e02e5dc5626d51aec21fdd (patch) | |
tree | d3a0c3caeb7003d2a63a738f32858d5b49229bd2 | |
parent | 952236ebfc2b985e26b5d40b7584de0655695a2f (diff) |
Extract method for checking whether a date is a weekend or a holiday
-rw-r--r-- | app/models/holiday.rb | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/app/models/holiday.rb b/app/models/holiday.rb index debd88dec..271fff3e1 100644 --- a/app/models/holiday.rb +++ b/app/models/holiday.rb @@ -25,15 +25,19 @@ class Holiday < ActiveRecord::Base + def Holiday.weekend_or_holiday?(date) + # TODO only fetch holidays after the start_date + holidays = self.all.collect { |h| h.day }.to_set + + date.wday == 0 || date.wday == 6 || holidays.include?(date) + end + # Calculate the date on which a request made on a given date falls due. # i.e. it is due by the end of that day. def Holiday.due_date_from(start_date, working_days) # convert date/times into dates start_date = start_date.to_date - # TODO only fetch holidays after the start_date - holidays = self.all.collect { |h| h.day }.to_set - # Count forward (20) working days. We start with today as "day zero". The # first of the twenty full working days is the next day. We return the # date of the last of the twenty. @@ -49,8 +53,7 @@ class Holiday < ActiveRecord::Base # Now step forward into each of the 20 days. while days_passed < working_days response_required_by += 1.day - next if response_required_by.wday == 0 || response_required_by.wday == 6 # weekend - next if holidays.include?(response_required_by) + next if weekend_or_holiday?(response_required_by) days_passed += 1 end |