bank-holiday-usa 0.1.1 → 0.2.0
raw patch · 6 files changed
+111/−27 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Data/Time/Calendar/BankHoliday/UnitedStates.hs +13/−8
- README.md +36/−14
- bank-holiday-usa.cabal +6/−4
- test/Data/Time/Calendar/BankHoliday/UnitedStatesSpec.hs +11/−0
- test/Data/Time/Calendar/BankHolidaySpec.hs +33/−0
- test/Spec.hs +12/−1
Data/Time/Calendar/BankHoliday/UnitedStates.hs view
@@ -12,9 +12,9 @@ ) where import Data.Maybe-import Data.Time (Day, fromGregorian, toGregorian)-import Data.Time.Calendar (addDays, toModifiedJulianDay)-import Data.Time.Calendar.BankHoliday (isWeekday, isWeekend, yearFromDay)+import Data.Time (Day, fromGregorian)+import Data.Time.Calendar (DayOfWeek (..), addDays, toModifiedJulianDay, dayOfWeek)+import Data.Time.Calendar.BankHoliday (yearFromDay) {- | bank holidays for a given year -} bankHolidays :: Integer -> [Day]@@ -28,7 +28,7 @@ , weekBefore (firstMondayIn jun) -- memorial day , firstMondayIn sep -- labor day , weekAfter (firstMondayIn oct) -- columbusDay- , 2 `weeksAfter` firstThursdayIn nov -- thanksgiving+ , 3 `weeksAfter` firstThursdayIn nov -- thanksgiving ] ++ catMaybes [ weekendHolidayFrom (jan 1) -- newYearsDay , weekendHolidayFrom (jul 4) -- independenceDay@@ -43,13 +43,13 @@ -- | day federal bank holidays were announced in the United States -- | March 9th 1933 filterHistoric :: [Day] -> [Day]-filterHistoric = filter (\d -> d > marchNinth1933)+filterHistoric = filter (> 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])+ concatMap bankHolidays [startYear..endYear] -- | find holidays falling between 2 specific days holidaysBetween :: Day -> Day -> [Day]@@ -66,9 +66,14 @@ -- | relative day helper functions weekIndex day = toModifiedJulianDay day `mod` 7-firstMondayIn month = addDays (negate $ weekIndex (month 02)) (month 07)-firstThursdayIn month = addDays 3 (firstMondayIn month)+firstMondayIn month = firstDayOfWeekOnAfter Monday (month 01)+firstThursdayIn month = firstDayOfWeekOnAfter Thursday (month 01) weeksBefore n = addDays (n * (-7)) weekBefore = weeksBefore 1 weeksAfter n = addDays (n * 7) weekAfter = weeksAfter 1++firstDayOfWeekOnAfter :: DayOfWeek -> Day -> Day+firstDayOfWeekOnAfter dw d = if dayOfWeek d == dw + then d + else firstDayOfWeekOnAfter dw (addDays 1 d)
README.md view
@@ -1,7 +1,8 @@-Holiday+Bank Holiday USA --- [](http://travis-ci.org/tippenein/BankHoliday)+[](http://hackage.haskell.org/package/bank-holiday-usa) A haskell library for holidays @@ -9,10 +10,41 @@ ---- +## usage++```haskell+-- list the 2016 bank holidays+bankHolidays 2016+[2016-01-18,2016-02-15,2016-05-30,2016-09-05,2016-10-10,2016-11-24,2016-01-01,2016-07-04,2016-11-11,2016-12-26]++-- isBankHoliday :: Day -> Bool+filter isBankHoliday [fromGregorian 2012 2 2, fromGregorian 2016 1 1]+[2016-01-01]++-- United States bank holidays started in 1933 on march 9th+holidaysBetweenYears 1900 1933+[1933-05-29,1933-09-04,1933-10-09,1933-11-23,1933-07-04,1933-12-25]++holidaysBetweenYears :: Day -> Day -> [Day]+```++``` sh++# Configure & build the package.+stack build++# Test package.+stack test++```++## Holidays++The holiday's covered:+ - New Year's Day - January 1-- Inauguration Day - January 20 - Martin Luther King, Jr. Day - Third Monday in January-- George Washington's Birthday - Third Monday in February+- George Washington's Birthday (President's day) - Third Monday in February - Memorial Day - Last Monday in May - Independence Day - July 4 - Labor Day - First Monday in September@@ -25,15 +57,5 @@ open the preceding Friday. For holidays falling on Sunday, all Federal Reserve Banks and Branches will be closed the following Monday. -``` sh--# Configure & build the package.-stack build--# Test package.-stack test--```--Inspired by [this](https://hackage.haskell.org/package/bank-holidays-england)+Inspired by [this](https://hackage.haskell.org/package/bank-holidays-england) library
bank-holiday-usa.cabal view
@@ -1,5 +1,5 @@ name: bank-holiday-usa-version: 0.1.1+version: 0.2.0 cabal-version: >=1.10 build-type: Simple license: MIT@@ -8,7 +8,7 @@ bug-reports: https://github.com/tippenein/BankHoliday/issues copyright: 2015 brady.ouren <brady.ouren@gmail.com> maintainer: brady.ouren <brady.ouren@gmail.com>-synopsis: A library for determining US bank holidays+synopsis: US bank holidays description: A library for determining US bank holidays category: Time@@ -24,12 +24,16 @@ build-depends: base ==4.* , time+ other-modules: default-language: Haskell2010 ghc-options: -Wall -fno-warn-missing-signatures test-suite tests type: exitcode-stdio-1.0 main-is: Spec.hs+ other-modules: + Data.Time.Calendar.BankHoliday.UnitedStatesSpec+ Data.Time.Calendar.BankHolidaySpec build-depends: base -any , bank-holiday-usa -any@@ -39,8 +43,6 @@ , QuickCheck -any default-language: Haskell2010 hs-source-dirs: test- other-modules: Spec- , Data.Time.Calendar.BankHoliday.UnitedStatesSpec ghc-options: -Wall -threaded -rtsopts source-repository head
test/Data/Time/Calendar/BankHoliday/UnitedStatesSpec.hs view
@@ -75,3 +75,14 @@ theRange `shouldContain` [e] theRange `shouldContain` [fromGregorian 2014 1 20] + describe "holidays depended on weekdays" $ do+ it "2021" $ do+ bankHolidays 2021 `shouldContain` [fromGregorian 2021 2 15] -- president day+ bankHolidays 2021 `shouldContain` [fromGregorian 2021 11 25] -- thanksgiving day+ it "2022" $ do+ bankHolidays 2022 `shouldContain` [fromGregorian 2022 2 21] -- president day+ bankHolidays 2022 `shouldContain` [fromGregorian 2022 11 24] -- thanksgiving day+ it "2023" $ do+ bankHolidays 2023 `shouldContain` [fromGregorian 2023 2 20] -- president day+ bankHolidays 2023 `shouldContain` [fromGregorian 2023 11 23] -- thanksgiving day+
+ test/Data/Time/Calendar/BankHolidaySpec.hs view
@@ -0,0 +1,33 @@+{-# LANGUAGE OverloadedStrings #-}++module Data.Time.Calendar.BankHolidaySpec (spec) where++import Data.Time+import Data.Time.Calendar.BankHoliday (isWeekday, isWeekend)+import Test.Hspec++spec :: Spec+spec = do+ describe "isWeekday" $ do+ it "is accurate" $ do+ all (\d -> isWeekday d) [+ (fromGregorian 1987 1 1)+ , (fromGregorian 1999 5 3)+ , (fromGregorian 1999 11 19)+ , (fromGregorian 2014 7 4)+ , (fromGregorian 2015 11 4)+ , (fromGregorian 2015 12 16)+ , (fromGregorian 2016 1 1)+ ]++ describe "isWeekend" $ do+ it "is accurate" $ do+ all (\d -> isWeekend d) [+ (fromGregorian 1987 1 10)+ , (fromGregorian 1999 11 20)+ , (fromGregorian 2015 11 15)+ , (fromGregorian 2015 12 12)+ , (fromGregorian 2015 7 4)+ , (fromGregorian 2015 12 13)+ , (fromGregorian 2015 11 14)+ ]
test/Spec.hs view
@@ -1,1 +1,12 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}+import Test.Hspec+import qualified Data.Time.Calendar.BankHoliday.UnitedStatesSpec as UnitedStates+import qualified Data.Time.Calendar.BankHolidaySpec as BankHoliday++main :: IO ()+main = hspec spec++spec :: Spec+spec = do+ UnitedStates.spec+ BankHoliday.spec+