module Holidays.DateTransform (
  substituteRule,
  sundayRule,
  DateTransform,
) where

import Data.Set qualified as S
import Data.Time
import Holidays.Base
import Holidays.DateFinder

type DateTransform = S.Set Holiday -> Holiday -> Holiday

-- | If day is on a sunday, it moves to monday
sundayRule :: DateTransform
sundayRule :: DateTransform
sundayRule Set Holiday
_ Holiday
d = if Day -> DayOfWeek
dayOfWeek Day
h DayOfWeek -> DayOfWeek -> Bool
forall a. Eq a => a -> a -> Bool
== DayOfWeek
Sunday then Holiday
d {holidayValue :: Day
holidayValue = Integer -> Day -> Day
addDays Integer
1 Day
h} else Holiday
d -- mon after sunday
  where
    h :: Day
h = Holiday -> Day
holidayValue Holiday
d

-- | Looks for next open day (day which is not a holiday), also skipping saturday and sunday
substituteRule :: DateTransform
substituteRule :: DateTransform
substituteRule = [DayOfWeek] -> DateTransform
nextOpenDay [DayOfWeek
Saturday, DayOfWeek
Sunday]