Class: Holidays::DateCalculator::WeekendModifier

Inherits:
Object
  • Object
show all
Defined in:
lib/holidays/date_calculator/weekend_modifier.rb

Instance Method Summary collapse

Instance Method Details

#to_monday_if_sunday(date) ⇒ Object

Move date to Monday if it occurs on a Sunday. Used as a callback function.



16
17
18
19
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 16

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.



8
9
10
11
12
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 8

def to_monday_if_weekend(date)
  date += 1 if date.wday == 0
  date += 2 if date.wday == 6
  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.



23
24
25
26
27
28
29
30
31
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 23

def to_weekday_if_boxing_weekend(date)
  if date.wday == 6 || date.wday == 0
    date += 2
  elsif date.wday == 1
    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.



35
36
37
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 35

def to_weekday_if_boxing_weekend_from_year(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.



42
43
44
45
46
# File 'lib/holidays/date_calculator/weekend_modifier.rb', line 42

def to_weekday_if_weekend(date)
  date += 1 if date.wday == 0
  date -= 1 if date.wday == 6
  date
end