module UsBankHolidays::DateMethods

Instance methods to be injected into the Date class

Public Instance Methods

add_banking_days(days) click to toggle source

Adds the given number of banking days, i.e. bank holidays don't count. If days is negative, subtracts the given number of banking days. If days is zero, returns self.

# File lib/us_bank_holidays.rb, line 85
def add_banking_days(days)
  day = self
  if days > 0
    days.times { day = day.next_banking_day }
  elsif days < 0
    (-days).times { day = day.previous_banking_day }
  end
  day
end
bank_holiday?(include_weekends = true) click to toggle source

Returns true if the date is a bank holiday, false otherwise. Pass the optional 'include_weekends' to control whether weekends should count as bank holidays (default is true). If include_weekends is set to false but the date is a Federal bank holiday, returns true (Ex: 4th of July, 2015, Christmas Day 2016)

# File lib/us_bank_holidays.rb, line 68
def bank_holiday?(include_weekends = true)
  ::UsBankHolidays.bank_holiday? self, include_weekends
end
banking_day?() click to toggle source

Returns true if this is a banking day, i.e. is not a bank holiday, false otherwise.

# File lib/us_bank_holidays.rb, line 97
def banking_day?
  !bank_holiday?
end
first_banking_day_of_month?() click to toggle source

Returns true if the date is the first banking day of the month, false otherwise.

# File lib/us_bank_holidays.rb, line 107
def first_banking_day_of_month?
  !bank_holiday? && previous_banking_day.month != month
end
last_banking_day_of_month?() click to toggle source

Returns true if the date is the last banking day of the month, false otherwise.

# File lib/us_bank_holidays.rb, line 102
def last_banking_day_of_month?
  !bank_holiday? && next_banking_day.month != month
end
next_banking_day() click to toggle source

Returns the next banking day after this one.

# File lib/us_bank_holidays.rb, line 73
def next_banking_day
  ::UsBankHolidays.next_banking_day self
end
previous_banking_day() click to toggle source

Returns the previous banking day

# File lib/us_bank_holidays.rb, line 78
def previous_banking_day
  ::UsBankHolidays.previous_banking_day self
end
weekend?() click to toggle source

Returns true if the date if a weekend, false otherwise.

# File lib/us_bank_holidays.rb, line 59
def weekend?
  ::UsBankHolidays.weekend? self
end