bank-holiday-usa 0.0.1 → 0.1.0
raw patch · 5 files changed
+61/−11 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Time.Calendar.BankHoliday: yearFromDay :: Day -> Integer
+ Data.Time.Calendar.BankHoliday.UnitedStates: holidaysBetween :: Day -> Day -> [Day]
+ Data.Time.Calendar.BankHoliday.UnitedStates: holidaysBetweenYears :: Integer -> Integer -> [Day]
Files
- Data/Time/Calendar/BankHoliday.hs +7/−1
- Data/Time/Calendar/BankHoliday/UnitedStates.hs +17/−4
- README.md +2/−3
- bank-holiday-usa.cabal +1/−1
- test/Data/Time/Calendar/BankHoliday/UnitedStatesSpec.hs +34/−2
Data/Time/Calendar/BankHoliday.hs view
@@ -1,11 +1,12 @@ --------------------------------------------------------------------------------- Module : Data.Time.Calendar.BankHoliday.UnitedStates+-- Module : Data.Time.Calendar.BankHoliday -- Maintainer : brady.ouren@gmail.com ------------------------------------------------------------------------------ module Data.Time.Calendar.BankHoliday ( isWeekend , isWeekday+ , yearFromDay ) where import Data.Time@@ -18,3 +19,8 @@ isWeekday :: Day -> Bool isWeekday = not . isWeekend +yearFromDay :: Day -> Integer+yearFromDay = fst' . toGregorian+ where+ fst' :: (a,b,c) -> a+ fst' (x,_,_) = x
Data/Time/Calendar/BankHoliday/UnitedStates.hs view
@@ -7,12 +7,14 @@ ( isBankHoliday , bankHolidays+ , holidaysBetween+ , holidaysBetweenYears ) where import Data.Maybe import Data.Time (Day, fromGregorian, toGregorian) import Data.Time.Calendar (addDays, toModifiedJulianDay)-import Data.Time.Calendar.BankHoliday (isWeekday, isWeekend)+import Data.Time.Calendar.BankHoliday (isWeekday, isWeekend, yearFromDay) {- | bank holidays for a given year -} bankHolidays :: Integer -> [Day]@@ -37,14 +39,25 @@ {- | whether the given day is a bank holiday -} isBankHoliday :: Day -> Bool-isBankHoliday d = d `elem` (bankHolidays year)- where- (year,_,_) = toGregorian d+isBankHoliday d = d `elem` bankHolidays (yearFromDay d) -- | day federal bank holidays were announced in the United States -- | March 9th 1933+filterHistoric :: [Day] -> [Day] filterHistoric = filter (\d -> d > marchNinth1933) where marchNinth1933 = fromGregorian 1933 3 9++-- | find holidays falling between 2 years of time+holidaysBetweenYears :: Integer -> Integer -> [Day]+holidaysBetweenYears startYear endYear =+ foldl (++) [] (map bankHolidays [startYear..endYear])++-- | find holidays falling between 2 specific days+holidaysBetween :: Day -> Day -> [Day]+holidaysBetween start end =+ filter (\a -> a >= start && a <= end) fullRange+ where+ fullRange = holidaysBetweenYears (yearFromDay start) (yearFromDay end) weekendHolidayFrom :: Day -> Maybe Day weekendHolidayFrom d = case weekIndex d of
README.md view
@@ -5,6 +5,8 @@ A haskell library for holidays +[bank-holiday-usa on hackage](https://hackage.haskell.org/package/bank-holiday-usa)+ ---- - New Year's Day - January 1@@ -24,9 +26,6 @@ Reserve Banks and Branches will be closed the following Monday. ``` sh--# Initialize a sandbox and install the package's dependencies.-stack install # Configure & build the package. stack build
bank-holiday-usa.cabal view
@@ -1,5 +1,5 @@ name: bank-holiday-usa-version: 0.0.1+version: 0.1.0 cabal-version: >=1.10 build-type: Simple license: MIT
test/Data/Time/Calendar/BankHoliday/UnitedStatesSpec.hs view
@@ -2,11 +2,12 @@ module Data.Time.Calendar.BankHoliday.UnitedStatesSpec (spec) where +import Data.List (nub) import Data.Time import Test.Hspec import Test.QuickCheck -import Data.Time.Calendar.BankHoliday (isWeekday)+import Data.Time.Calendar.BankHoliday (isWeekday, yearFromDay) import Data.Time.Calendar.BankHoliday.UnitedStates spec :: Spec@@ -27,5 +28,36 @@ describe "isBankHoliday" $ do it "returns true for the days we expect" $ do let christmas = fromGregorian 2015 12 25- isBankHoliday christmas `shouldBe` True+ let newYears = fromGregorian 2014 1 1+ let fourth = fromGregorian 2014 7 4+ all isBankHoliday [christmas, newYears, fourth]++ describe "holidaysBetweenYears" $ do+ it "does not include dates outside of range" $ do+ let tooEarly = bankHolidays 1999+ let tooLate = bankHolidays 2017+ let justRight = holidaysBetweenYears 2000 2016+ justRight `shouldNotContain` tooEarly+ justRight `shouldNotContain` tooLate++ it "keeps them in order" $ do+ let oneYearRange = holidaysBetweenYears 2000 2001+ let f = yearFromDay $ head $ oneYearRange+ let l = yearFromDay $ head $ reverse $ oneYearRange+ f `shouldBe` 2000+ l `shouldBe` 2001++ it "does not duplicate if given the same year" $ do+ let sameYearRange = holidaysBetweenYears 2000 2000+ nub sameYearRange `shouldBe` sameYearRange+++ describe "holidaysBetween" $ do+ it "does not include dates outside of range" $ do+ let (s, e) = (fromGregorian 2014 1 2, fromGregorian 2014 7 4)+ let theRange = holidaysBetween s e+ theRange `shouldNotContain` [fromGregorian 2014 1 1]+ theRange `shouldNotContain` [fromGregorian 2014 7 5]+ theRange `shouldContain` [e]+ theRange `shouldContain` [fromGregorian 2014 1 20]