class UsBankHolidays::HolidayYear
Utility class to calculate where the federal holidays will actually fall for any given year.
Attributes
christmas[R]
columbus_day[R]
independence_day[R]
juneteenth[R]
labor_day[R]
memorial_day[R]
mlk_day[R]
new_years_day[R]
thanksgiving[R]
veterans_day[R]
washingtons_birthday[R]
year[R]
Public Class Methods
new(year)
click to toggle source
Initializes instance from a given year
# File lib/us_bank_holidays/holiday_year.rb, line 21 def initialize(year) @year = year init_fixed_holidays init_rolled_holidays end
Public Instance Methods
bank_holidays()
click to toggle source
Returns the federal holidays for the given year on the dates they will actually be observed.
# File lib/us_bank_holidays/holiday_year.rb, line 31 def bank_holidays @bank_holidays ||= begin holidays = [ new_years_day, mlk_day, washingtons_birthday, memorial_day, juneteenth, independence_day, labor_day, columbus_day, veterans_day, thanksgiving, christmas ].compact if Date.new(year + 1, 1, 1).saturday? holidays << Date.new(year, 12, 31) end holidays.freeze end end
Private Instance Methods
init_fixed_holidays()
click to toggle source
These holidays are always fixed
# File lib/us_bank_holidays/holiday_year.rb, line 77 def init_fixed_holidays # Third Monday of January @mlk_day = january.mondays[2] # Third Monday of February @washingtons_birthday = february.mondays[2] # Last Monday of May @memorial_day = may.mondays.last # First Monday of September @labor_day = september.mondays.first # Second Monday of October @columbus_day = october.mondays[1] # Fourth Thursday of November @thanksgiving = november.thursdays[3] end
init_rolled_holidays()
click to toggle source
These holidays are potentially rolled if they come on a weekend.
# File lib/us_bank_holidays/holiday_year.rb, line 98 def init_rolled_holidays # First of the year, rolls either forward or back. @new_years_day = roll_nominal(Date.new(year, 1, 1)) # 19th of June @juneteenth = (year > 2020 ? roll_nominal(Date.new(year, 6, 19)) : nil ) # 4th of July @independence_day = roll_nominal(Date.new(year, 7, 4)) # November 11 @veterans_day = roll_nominal(Date.new(year, 11, 11)) # December 25 @christmas = roll_nominal(Date.new(year, 12, 25)) end
roll_nominal(nominal)
click to toggle source
Figures out where to roll the given nominal date. If it's a Saturday and Saturday holiday date rolling is enabled (see UsBankHolidays#saturday_holiday_date_rolling?), assumes it's the day before (Friday), if Sunday it's the date after (Monday), otherwise just returns self.
# File lib/us_bank_holidays/holiday_year.rb, line 119 def roll_nominal(nominal) if nominal.saturday? && ::UsBankHolidays.saturday_holiday_date_rolling? nominal - 1 elsif nominal.sunday? nominal + 1 else nominal end end