Class: Holidays::DateCalculator::WeekendModifier
- Inherits:
-
Object
- Object
- Holidays::DateCalculator::WeekendModifier
- Defined in:
- lib/holidays/date_calculator/weekend_modifier.rb
Instance Method Summary collapse
-
#to_monday_if_sunday(date) ⇒ Object
Move date to Monday if it occurs on a Sunday.
-
#to_monday_if_weekend(date) ⇒ Object
Move date to Monday if it occurs on a Saturday on Sunday.
-
#to_tuesday_if_sunday_or_monday_if_saturday(date) ⇒ Object
if Christmas falls on a Saturday, move it to the next Monday (Boxing Day will be Sunday and potentially Tuesday) if Christmas falls on a Sunday, move it to the next Tuesday (Boxing Day will go on Monday).
-
#to_weekday_if_boxing_weekend(date) ⇒ Object
Move Boxing Day if it falls on a weekend, leaving room for Christmas.
-
#to_weekday_if_boxing_weekend_from_year(year) ⇒ Object
Call to_weekday_if_boxing_weekend but first get date based on year Used as a callback function.
-
#to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday(year) ⇒ Object
Call to_weekday_if_boxing_weekend but first get date based on year Used as a callback function.
-
#to_weekday_if_weekend(date) ⇒ Object
Move date to Monday if it occurs on a Sunday or to Friday if it occurs on a Saturday.
-
#xmas_to_weekday_if_weekend(year) ⇒ Object
if Christmas falls on a Sunday, move it to the next Tuesday (Boxing Day will go on Monday) if Christmas falls on a Saturday, move it to the next Monday (Boxing Day will be Sunday and potentially Tuesday) used as a callback function, if xmas is not observed on the 25th.
Instance Method Details
#to_monday_if_sunday(date) ⇒ Object
Move date to Monday if it occurs on a Sunday. Used as a callback function.
14 15 16 17 |
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 14 def to_monday_if_sunday(date) date += 1 if date.wday == 0 date end |
#to_monday_if_weekend(date) ⇒ Object
Move date to Monday if it occurs on a Saturday on Sunday. Used as a callback function.
6 7 8 9 10 |
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 6 def to_monday_if_weekend(date) date += 1 if date.wday == 0 date += 2 if date.wday == 6 date end |
#to_tuesday_if_sunday_or_monday_if_saturday(date) ⇒ Object
if Christmas falls on a Saturday, move it to the next Monday (Boxing Day will be Sunday and potentially Tuesday) if Christmas falls on a Sunday, move it to the next Tuesday (Boxing Day will go on Monday)
if Boxing Day falls on a Saturday, move it to the next Monday (Christmas will go on Friday) if Boxing Day falls on a Sunday, move it to the next Tuesday (Christmas will go on Saturday & Monday)
43 44 45 46 |
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 43 def to_tuesday_if_sunday_or_monday_if_saturday(date) date += 2 if [0, 6].include?(date.wday) date end |
#to_weekday_if_boxing_weekend(date) ⇒ Object
Move Boxing Day if it falls on a weekend, leaving room for Christmas. Used as a callback function.
28 29 30 31 32 33 34 35 36 |
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 28 def to_weekday_if_boxing_weekend(date) if date.wday == 6 || date.wday == 0 date += 2 elsif date.wday == 1 # https://github.com/holidays/holidays/issues/27 date += 1 end date end |
#to_weekday_if_boxing_weekend_from_year(year) ⇒ Object
Call to_weekday_if_boxing_weekend but first get date based on year Used as a callback function.
56 57 58 |
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 56 def to_weekday_if_boxing_weekend_from_year(year) to_tuesday_if_sunday_or_monday_if_saturday(Date.civil(year, 12, 26)) end |
#to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday(year) ⇒ Object
Call to_weekday_if_boxing_weekend but first get date based on year Used as a callback function.
50 51 52 |
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 50 def to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday(year) to_weekday_if_boxing_weekend(Date.civil(year, 12, 26)) end |
#to_weekday_if_weekend(date) ⇒ Object
Move date to Monday if it occurs on a Sunday or to Friday if it occurs on a Saturday. Used as a callback function.
63 64 65 66 67 |
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 63 def to_weekday_if_weekend(date) date += 1 if date.wday == 0 date -= 1 if date.wday == 6 date end |
#xmas_to_weekday_if_weekend(year) ⇒ Object
if Christmas falls on a Sunday, move it to the next Tuesday (Boxing Day will go on Monday) if Christmas falls on a Saturday, move it to the next Monday (Boxing Day will be Sunday and potentially Tuesday) used as a callback function, if xmas is not observed on the 25th
22 23 24 |
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 22 def xmas_to_weekday_if_weekend(year) to_tuesday_if_sunday_or_monday_if_saturday(Date.civil(year, 12, 25)) end |