Module: Useful::RubyExtensions::Date

Included in:
Date
Defined in:
lib/useful/ruby_extensions/date.rb

Instance Method Summary collapse

Instance Method Details

#week_days_until(end_date) ⇒ Object

Raises:

  • (::ArgumentError)


5
6
7
8
9
10
# File 'lib/useful/ruby_extensions/date.rb', line 5

def week_days_until(end_date)
  week_days = (1..5)
  raise ::ArgumentError, "End date cannot be nil." if end_date.nil?
  raise ::ArgumentError, "End date cannot come before questioned date." if end_date < self
  (self..end_date).to_a.select{|date| week_days.include?(date.wday)}.length
end