class Holidays::DateCalculator::WeekendModifier

def to_monday_if_sunday(date)

Used as a callback function.
Does not modify the date if it is not a Sunday.
Move date to Monday if it occurs on a Sunday.
def to_monday_if_sunday(date)
  return date unless date.wday == 0
  to_next_weekday(date)
end

def to_monday_if_weekend(date)

Used as a callback function.
Does not modify date if it is not a weekend.
Move date to Monday if it occurs on a Saturday on Sunday.
def to_monday_if_weekend(date)
  return date unless date.wday == 6 || date.wday == 0
  to_next_weekday(date)
end

def to_next_weekday(date)

if Saturday return Monday, if Tuesday return Wednesday, etc.
it will return the following Monday. If Sunday then return Monday,
Finds the next weekday. For example, if a 'Friday' date is received
def to_next_weekday(date)
  case date.wday
  when 6
    date += 2
  when 5
    date += 3
  else
    date += 1
  end
  date
end

def to_tuesday_if_sunday_or_monday_if_saturday(date)

if Boxing Day falls on a Sunday, move it to the next Tuesday (Christmas will go on Saturday & Monday)
if Boxing Day falls on a Saturday, move it to the next Monday (Christmas will go on Friday)

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)
def to_tuesday_if_sunday_or_monday_if_saturday(date)
  date += 2 if [0, 6].include?(date.wday)
  date
end

def to_weekday_if_boxing_weekend(date)

Used as a callback function.
Move Boxing Day if it falls on a weekend, leaving room for Christmas.
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

def to_weekday_if_boxing_weekend_from_year(year)

Used as a callback function.
Call to_weekday_if_boxing_weekend but first get date based on year
def to_weekday_if_boxing_weekend_from_year(year)
  to_tuesday_if_sunday_or_monday_if_saturday(Date.civil(year, 12, 26))
end

def to_weekday_if_boxing_weekend_from_year_or_to_tuesday_if_monday(year)

Used as a callback function.
Call to_weekday_if_boxing_weekend but first get date based on year
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

def to_weekday_if_weekend(date)

Used as a callback function.
Saturday.
Move date to Monday if it occurs on a Sunday or to Friday if it occurs on a
def to_weekday_if_weekend(date)
  date += 1 if date.wday == 0
  date -= 1 if date.wday == 6
  date
end