fix(holidays): minor improvement to memoization
This commit is contained in:
parent
d69cacc027
commit
f411fde42d
@ -2,7 +2,8 @@
|
|||||||
Module: Utils.Holidays
|
Module: Utils.Holidays
|
||||||
Description: German bank holidays
|
Description: German bank holidays
|
||||||
|
|
||||||
Following module Data.Time.Calendar.BankHoliday.EnglandAndWales
|
Interfaces follows module Data.Time.Calendar.BankHoliday.EnglandAndWales
|
||||||
|
isBankHolidayArea uses laziness to provide some simple memoization for a fixed range of years
|
||||||
-}
|
-}
|
||||||
module Utils.Holidays
|
module Utils.Holidays
|
||||||
( Feiertagsgebiet(..)
|
( Feiertagsgebiet(..)
|
||||||
@ -13,7 +14,7 @@ module Utils.Holidays
|
|||||||
|
|
||||||
import Import.NoModel
|
import Import.NoModel
|
||||||
|
|
||||||
import qualified Data.Set as Set (Set, member, unions)
|
import qualified Data.Set as Set (Set, member)
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
--import Data.Time.Calendar.WeekDate
|
--import Data.Time.Calendar.WeekDate
|
||||||
@ -112,12 +113,16 @@ isBankHolidayArea land dd = dd `Set.member` holidays
|
|||||||
holidays
|
holidays
|
||||||
| year >= cacheMinYear
|
| year >= cacheMinYear
|
||||||
, year <= cacheMaxYear
|
, year <= cacheMaxYear
|
||||||
, (Just hds) <- Map.lookup land cacheHolidays = hds
|
, (Just hys) <- Map.lookup land cacheHolidays
|
||||||
|
, (Just hds) <- Map.lookup year hys = hds
|
||||||
| otherwise = bankHolidaysAreaSet land year
|
| otherwise = bankHolidaysAreaSet land year
|
||||||
|
|
||||||
cacheMinYear, cacheMaxYear :: Integer
|
cacheMinYear, cacheMaxYear :: Integer
|
||||||
cacheMinYear = 2020
|
cacheMinYear = 2020
|
||||||
cacheMaxYear = 2075
|
cacheMaxYear = 2075
|
||||||
|
|
||||||
cacheHolidays :: Map.Map Feiertagsgebiet (Set.Set Day)
|
cacheHolidays :: Map.Map Feiertagsgebiet (Map.Map Integer (Set.Set Day))
|
||||||
cacheHolidays = Map.fromList [ (land, Set.unions $ bankHolidaysAreaSet land <$> [cacheMinYear..cacheMaxYear]) | land <- universeF ]
|
cacheHolidays = Map.fromList [(land, Map.fromList
|
||||||
|
[(year, bankHolidaysAreaSet land year)
|
||||||
|
| year <- [cacheMinYear..cacheMaxYear]])
|
||||||
|
| land <- universeF]
|
||||||
Reference in New Issue
Block a user