Module: NorwegianHolidays
- Defined in:
- lib/norwegian_holidays.rb
Class Method Summary collapse
- .christmas(year) ⇒ Object
- .christmas_eve(year) ⇒ Object
- .days_til_sunday(date) ⇒ Object
- .fathersday(year) ⇒ Object
- .holiday_for_season(holiday, date, timeframe = 0) ⇒ Object
- .mothersday(year) ⇒ Object
- .next_holiday(holiday, given_date) ⇒ Object
- .second_sunday_in(month, year) ⇒ Object
- .valentines_day(year) ⇒ Object
Class Method Details
.christmas(year) ⇒ Object
11 12 13 |
# File 'lib/norwegian_holidays.rb', line 11 def christmas(year) Date.new(year, 12, 25) end |
.christmas_eve(year) ⇒ Object
7 8 9 |
# File 'lib/norwegian_holidays.rb', line 7 def christmas_eve(year) Date.new(year, 12, 24) end |
.days_til_sunday(date) ⇒ Object
32 33 34 |
# File 'lib/norwegian_holidays.rb', line 32 def days_til_sunday(date) (7 - date.wday) % 7 end |
.fathersday(year) ⇒ Object
19 20 21 |
# File 'lib/norwegian_holidays.rb', line 19 def fathersday(year) second_sunday_in(11, year) end |
.holiday_for_season(holiday, date, timeframe = 0) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/norwegian_holidays.rb', line 46 def holiday_for_season(holiday, date, timeframe = 0) upcoming = next_holiday(holiday, date) if (date + timeframe) >= upcoming upcoming else send(holiday, upcoming.year - 1) end end |
.mothersday(year) ⇒ Object
23 24 25 |
# File 'lib/norwegian_holidays.rb', line 23 def mothersday(year) second_sunday_in(2, year) end |
.next_holiday(holiday, given_date) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/norwegian_holidays.rb', line 36 def next_holiday(holiday, given_date) the_day = self.send(holiday.to_sym, given_date.year) if the_day < given_date the_day = self.send(holiday.to_sym, given_date.year + 1) end the_day end |
.second_sunday_in(month, year) ⇒ Object
27 28 29 30 |
# File 'lib/norwegian_holidays.rb', line 27 def second_sunday_in(month, year) second_week = Date.new(year, month, 8) second_week + days_til_sunday(second_week) end |
.valentines_day(year) ⇒ Object
15 16 17 |
# File 'lib/norwegian_holidays.rb', line 15 def valentines_day(year) Date.new(year, 2, 14) end |