Module: Holidays::Definition::CustomMethods::US
- Defined in:
- lib/holidays/definition/custom_methods/us.rb
Overview
us custom holiday calculations, ported verbatim from the
methods: block in definitions/us.yaml.
Class Method Summary collapse
- .christmas_eve_holiday(date) ⇒ Object
- .election_day(year) ⇒ Object
- .even_year_election_day(year) ⇒ Object
- .georgia_state_holiday(year, month) ⇒ Object
- .juneteenth_national_independence_day(region, date) ⇒ Object
- .lee_jackson_day(year, month) ⇒ Object
- .rosh_hashanah(year) ⇒ Object
- .us_inauguration_day(year) ⇒ Object
- .yom_kippur(year) ⇒ Object
Class Method Details
.christmas_eve_holiday(date) ⇒ Object
10 11 12 13 |
# File 'lib/holidays/definition/custom_methods/us.rb', line 10 def christmas_eve_holiday(date) beginning_of_month = Date.civil(date.year, date.month, 1) (date.saturday? || date.sunday?) ? date.downto(beginning_of_month).find {|d| d if d.wday == 5} : date end |
.election_day(year) ⇒ Object
75 76 77 |
# File 'lib/holidays/definition/custom_methods/us.rb', line 75 def election_day(year) Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 11, 1, 1) + 1 end |
.even_year_election_day(year) ⇒ Object
79 80 81 82 83 |
# File 'lib/holidays/definition/custom_methods/us.rb', line 79 def even_year_election_day(year) if year % 2 == 0 Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, 11, 1, 1) + 1 end end |
.georgia_state_holiday(year, month) ⇒ Object
41 42 43 44 45 |
# File 'lib/holidays/definition/custom_methods/us.rb', line 41 def georgia_state_holiday(year, month) beginning_of_month = Date.civil(year, month, 1) state_holiday = Date.civil(year, month, 26) state_holiday.downto(beginning_of_month).find {|date| date if date.wday == 1 } end |
.juneteenth_national_independence_day(region, date) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/holidays/definition/custom_methods/us.rb', line 54 def juneteenth_national_independence_day(region, date) if region == :us_ut case date.wday when 1 date when 2,3,4,5 date - (date.wday - 1) when 6 date + 2 when 0 date + 1 end elsif date.wday == 0 date + 1 elsif date.wday == 6 date - 1 else date end end |
.lee_jackson_day(year, month) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/holidays/definition/custom_methods/us.rb', line 47 def lee_jackson_day(year, month) day_of_holiday = Holidays::Factory::DateCalculator.day_of_month_calculator.call(year, month, 3, 1) beginning_of_month = Date.civil(year, month, 1) king_day = Date.civil(year, month, day_of_holiday) king_day.downto(beginning_of_month).find {|date| date if date.wday == 5 } end |
.rosh_hashanah(year) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/holidays/definition/custom_methods/us.rb', line 15 def rosh_hashanah(year) rosh_hashanah_dates = { '2014' => Date.civil(2014, 9, 25), '2015' => Date.civil(2015, 9, 14), '2016' => Date.civil(2016, 10, 3), '2017' => Date.civil(2017, 9, 21), '2018' => Date.civil(2018, 9, 10), '2019' => Date.civil(2019, 9, 30), '2020' => Date.civil(2020, 9, 19) } rosh_hashanah_dates[year.to_s] end |
.us_inauguration_day(year) ⇒ Object
85 86 87 |
# File 'lib/holidays/definition/custom_methods/us.rb', line 85 def us_inauguration_day(year) year % 4 == 1 ? 20 : nil end |
.yom_kippur(year) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/holidays/definition/custom_methods/us.rb', line 28 def yom_kippur(year) yom_kippur_dates = { '2014' => Date.civil(2014, 10, 4), '2015' => Date.civil(2015, 9, 23), '2016' => Date.civil(2016, 10, 12), '2017' => Date.civil(2017, 9, 30), '2018' => Date.civil(2018, 9, 19), '2019' => Date.civil(2019, 10, 9), '2020' => Date.civil(2020, 9, 28) } yom_kippur_dates[year.to_s] end |