bank-holiday-germany 1.1.0.0 → 1.2.0.0
raw patch · 4 files changed
+52/−11 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Time.Calendar.BankHoliday.Germany.ExtraHolidays: Reformationstag :: ExtraHoliday
Files
- bank-holiday-germany.cabal +1/−1
- src/Data/Time/Calendar/BankHoliday/Germany.hs +1/−1
- src/Data/Time/Calendar/BankHoliday/Germany/ExtraHolidays.hs +28/−6
- test/Main.hs +22/−3
bank-holiday-germany.cabal view
@@ -1,7 +1,7 @@ cabal-version: 3.6 name: bank-holiday-germany-version: 1.1.0.0+version: 1.2.0.0 synopsis: German bank holidays and public holidays description: Calculation of bank holidays and most public holidays in Germany. homepage: https://github.com/schoettl/bank-holiday-germany#readme
src/Data/Time/Calendar/BankHoliday/Germany.hs view
@@ -133,7 +133,7 @@ fromDay :: Day -> Maybe BankHoliday fromDay day = listToMaybe $ filter (\d -> day == toDay (yearFromDay day) d) [minBound..maxBound] --- | Compute pairs of date and holiday from start to end.+-- | Compute pairs of date and holiday from start to end (inclusive). -- -- Note: In some years, two bank holidays can fall on the same -- day. In such cases only one of them is in the resulting list.
src/Data/Time/Calendar/BankHoliday/Germany/ExtraHolidays.hs view
@@ -16,7 +16,9 @@ For example, Heilige Drei Könige is not a bank holiday but it is a public holiday in Bavaria. -Note: The extra holidays are currently only implemented for Bavaria.+Note: The extra holidays are currently only implemented for+Baden-Württemberg, Bayern, Berlin, Niedersachsen, Hessen, and+Nordrhein-Westfalen. Example for computing all public holidays in Bavaria (Landkreis Miesbach, Oberbayern) in the next couple years:@@ -74,6 +76,9 @@ - Übersicht: https://de.wikipedia.org/wiki/Gesetzliche_Feiertage_in_Deutschland - Weitere Übersicht: https://www.arbeitstage.org/ - Bayern: https://www.stmi.bayern.de/suv/feiertage/+ - Baden-Württemberg: https://im.baden-wuerttemberg.de/de/service/feiertage+ - Niedersachsen: https://service.niedersachsen.de/portaldeeplink/?tsa_leistung_id=8664664&tsa_sprache=de_DE+ - Hessen: https://innen.hessen.de/buerger-staat/feiertage -} @@ -112,17 +117,21 @@ | Thueringen deriving (Enum, Eq, Bounded, Show, Read) +-- TODO: Remove note below when all federal states are fully implemented.+ -- | Extra federal holidays, no overlap with -- 'Data.Time.Calendar.BankHoliday.Germany.BankHoliday'. -- Spezielle Feiertage der Bundesländer. ----- Note: Currently, only Bavaria's extra holidays are implemented.+-- Note: Currently, only some federal states' extra holidays are implemented.+-- See module description above for details. data ExtraHoliday- = HeiligeDreiKoenige -- ^ Heilige Drei Könige (Bayern, …)- | Fronleichnam -- ^ Fronleichnam (Bayern, …)+ = HeiligeDreiKoenige -- ^ Heilige Drei Könige (Bayern, Baden-Württemberg, …)+ | Fronleichnam -- ^ Fronleichnam (Bayern, Baden-Württemberg, Nordrhein-Westfalen, Hessen, …) | Friedensfest -- ^ Friedensfest (Bayern (Augsburg), …) | MariaeHimmelfahrt -- ^ Mariä Himmelfahrt (Bayern (regional), …)- | Allerheiligen -- ^ Allerheiligen (Bayern, …)+ | Allerheiligen -- ^ Allerheiligen (Bayern, Baden-Württemberg, Nordrhein-Westfalen, …)+ | Reformationstag -- ^ Reformationstag (Niedersachsen, …) | InternationalerFrauentag -- ^ Internationaler Frauentag (Berlin, …) deriving (Enum, Eq, Bounded, Show, Read) @@ -137,9 +146,14 @@ toDay year MariaeHimmelfahrt = fromGregorian year 8 15 toDay year Allerheiligen = fromGregorian year 11 1 toDay year InternationalerFrauentag = fromGregorian year 3 8+toDay year Reformationstag = fromGregorian year 10 31 -- | Compute 'Maybe' the holiday for a given date. --+-- Note: In some years, two extra holidays may fall on the same+-- day. In such cases this function returns the holiday+-- that is defined first in the 'ExtraHoliday' 'Enum'.+-- -- >>> fromDay (fromGregorian 2024 11 1) -- Just Allerheiligen --@@ -148,7 +162,7 @@ fromDay :: Day -> Maybe ExtraHoliday fromDay day = listToMaybe $ filter (\d -> day == toDay (yearFromDay day) d) [minBound..maxBound] --- | Compute pairs of date and holiday from start to end for the given federal state.+-- | Compute pairs of date and holiday from start to end (inclusive) for the given federal state. -- -- >>> map snd $ holidaysBetween Bayern (fromGregorian 2024 8 8) (fromGregorian 2024 8 15) -- [Friedensfest,MariaeHimmelfahrt]@@ -163,6 +177,7 @@ Friedensfest -> "Friedensfest" MariaeHimmelfahrt -> "Mariä Himmelfahrt" Allerheiligen -> "Allerheiligen"+ Reformationstag -> "Reformationstag" InternationalerFrauentag -> "Internationaler Frauentag" -- | Check if 'ExtraHoliday' is a holiday in the given federal state.@@ -173,10 +188,17 @@ -- >>> isHolidayInState Berlin Allerheiligen -- False isHolidayInState :: FederalState -> ExtraHoliday -> Bool+isHolidayInState BadenWuerttemberg HeiligeDreiKoenige = True+isHolidayInState BadenWuerttemberg Fronleichnam = True+isHolidayInState BadenWuerttemberg Allerheiligen = True isHolidayInState Bayern HeiligeDreiKoenige = True isHolidayInState Bayern Fronleichnam = True isHolidayInState Bayern Friedensfest = True isHolidayInState Bayern MariaeHimmelfahrt = True isHolidayInState Bayern Allerheiligen = True isHolidayInState Berlin InternationalerFrauentag = True+isHolidayInState NordrheinWestfalen Fronleichnam = True+isHolidayInState NordrheinWestfalen Allerheiligen = True+isHolidayInState Niedersachsen Reformationstag = True+isHolidayInState Hessen Fronleichnam = True isHolidayInState _ _ = False
test/Main.hs view
@@ -16,6 +16,12 @@ day :: Year -> Int -> Int -> Day day = fromGregorian +jan1 :: Year -> Day+jan1 y = fromGregorian y 1 1++dec31 :: Year -> Day+dec31 y = fromGregorian y 12 31+ year :: Day -> Year year = (\(y, _, _) -> y) . toGregorian @@ -33,7 +39,7 @@ `shouldBe` [] it "counts 11 bank holidays and 9 public holidays per year (2010 to 2020)" $ hedgehog $ do y <- forAll $ Gen.integral (Range.linear 2010 2020)- let bankHolidays = holidaysBetween (day y 1 1) (day y 12 31)+ let bankHolidays = holidaysBetween ((jan1 y)) ((dec31 y)) length bankHolidays === 11 length (filter (isPublicHoliday . snd) bankHolidays) === 9 describe "toDay" $ do@@ -79,13 +85,26 @@ map (\y -> show $ EH.toDay y Fronleichnam) [2024..2027] `shouldBe` ["2024-05-30", "2025-06-19", "2026-06-04", "2027-05-27"] describe "holidaysBetween" $ do- it "only has Bavaria's extra holidays" $+ it "yields Bavaria's extra holidays" $ map snd (EH.holidaysBetween Bayern (day 2024 11 1) (day 2024 12 31)) `shouldBe` [Allerheiligen] it "there is only one extra holiday in Berlin" $ do filter (EH.isHolidayInState Berlin) [minBound..maxBound] `shouldBe` [InternationalerFrauentag]+ it "there are 3 extra holidays in Baden-Württemberg" $ hedgehog $ do+ y <- forAll $ Gen.integral (Range.linear 2024 5000)+ length (EH.holidaysBetween BadenWuerttemberg ((jan1 y)) ((dec31 y))) === 3+ it "there are 2 extra holidays in Nordrhein-Westfalen" $ hedgehog $ do+ y <- forAll $ Gen.integral (Range.linear 2024 5000)+ length (EH.holidaysBetween NordrheinWestfalen ((jan1 y)) ((dec31 y))) === 2+ it "there is only 1 extra holiday in Niedersachsen" $ hedgehog $ do+ y <- forAll $ Gen.integral (Range.linear 2024 5000)+ length (EH.holidaysBetween Niedersachsen (jan1 y) (dec31 y)) === 1+ it "there is only Fronleichnam in Hessen" $ hedgehog $ do+ y <- forAll $ Gen.integral (Range.linear 2024 5000)+ (map snd $ EH.holidaysBetween Hessen (jan1 y) (dec31 y)) === [Fronleichnam] it "has no holidays for other states yet => otherwise, please add tests" $ do- let statesExceptBavaria = filter (not . flip elem [Bayern, Berlin]) [minBound..maxBound]+ let statesExceptBavaria = filter (not . (`elem` [BadenWuerttemberg, Bayern, Berlin, NordrheinWestfalen, Niedersachsen, Hessen])) [minBound .. maxBound :: FederalState] let holidays = concatMap (\x -> EH.holidaysBetween x (day 2024 1 1) (day 2024 12 31)) statesExceptBavaria holidays `shouldBe` []+ -- TODO: add test for germanHolidayName that uses random holidays to detect non-exhaustive patterns