Module: DigitalOpera::BusinessDayCalculations

Included in:
Date, Time
Defined in:
lib/is_business_day/digitalopera/business_day_calculations.rb

Instance Method Summary collapse

Instance Method Details

#is_a_business_day?Boolean

Returns TRUE || FALSE if the date is a valid business day this also accounts for holidays

Returns:

  • (Boolean)


10
11
12
# File 'lib/is_business_day/digitalopera/business_day_calculations.rb', line 10

def is_a_business_day?
  (self.monday? || self.tuesday? || self.wednesday? || self.thursday? || self.friday?) && self.is_not_a_holiday?
end

#is_not_a_business_day?Boolean

Returns TRUE || FALSE if the date IS NOT a valid business day this also accounts for holidays

Returns:

  • (Boolean)


17
18
19
# File 'lib/is_business_day/digitalopera/business_day_calculations.rb', line 17

def is_not_a_business_day?
  self.saturday? || self.sunday? || self.is_a_holiday?
end

#next_business_dayObject

Returns the first business day following the date. This will account for ANY non-business day, holidays included.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/is_business_day/digitalopera/business_day_calculations.rb', line 24

def next_business_day
  next_business_day = self

  begin
    next_business_day = (next_business_day.to_time + 1.day).to_date
  end while next_business_day.is_not_a_business_day?

  if self.class.name == "Time"
    return next_business_day.to_time
  else
    return next_business_day
  end
end

#previous_business_dayObject

Returns the first business day preceding the date. This will account for ANY non-business day, holidays included.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/is_business_day/digitalopera/business_day_calculations.rb', line 41

def previous_business_day
  previous_business_day = self

  begin
    previous_business_day = (previous_business_day.to_time - 1.day).to_date
  end while previous_business_day.is_not_a_business_day?

  if self.class.name == "Time"
    return previous_business_day.to_time
  else
    return previous_business_day
  end
end