packages feed

bank-holiday-usa (empty) → 0.0.1

raw patch · 8 files changed

+225/−0 lines, 8 filesdep +HUnitdep +QuickCheckdep +bank-holiday-usasetup-changed

Dependencies added: HUnit, QuickCheck, bank-holiday-usa, base, hspec, time

Files

+ Data/Time/Calendar/BankHoliday.hs view
@@ -0,0 +1,20 @@+------------------------------------------------------------------------------+-- Module      : Data.Time.Calendar.BankHoliday.UnitedStates+-- Maintainer  : brady.ouren@gmail.com+------------------------------------------------------------------------------++module Data.Time.Calendar.BankHoliday+  ( isWeekend+  , isWeekday+  ) where++import Data.Time++{- | whether the given day is a weekend -}+isWeekend :: Day -> Bool+isWeekend d = toModifiedJulianDay d `mod` 7 `elem` [3,4]++{- | whether the given day is a weekday -}+isWeekday :: Day -> Bool+isWeekday = not . isWeekend+
+ Data/Time/Calendar/BankHoliday/UnitedStates.hs view
@@ -0,0 +1,62 @@+------------------------------------------------------------------------------+-- Module      : Data.Time.Calendar.BankHoliday.UnitedStates+-- Maintainer  : brady.ouren@gmail.com+------------------------------------------------------------------------------++module Data.Time.Calendar.BankHoliday.UnitedStates+  (+    isBankHoliday+  , bankHolidays+  ) where++import Data.Maybe+import Data.Time (Day, fromGregorian, toGregorian)+import Data.Time.Calendar (addDays, toModifiedJulianDay)+import Data.Time.Calendar.BankHoliday (isWeekday, isWeekend)++{- | bank holidays for a given year -}+bankHolidays :: Integer -> [Day]+bankHolidays year = filterHistoric standardHolidays+  where+    [jan, feb, jun, jul, sep, oct, nov, dec] = monthsMap+    monthsMap = map (fromGregorian year) [1,2,6,7,9,10,11,12]+    standardHolidays = [+        2 `weeksBefore` firstMondayIn feb  -- mlk Day+      , 2 `weeksAfter` firstMondayIn feb   -- presidents day+      , weekBefore (firstMondayIn jun)     -- memorial day+      , firstMondayIn sep                  -- labor day+      , weekAfter (firstMondayIn oct)      -- columbusDay+      , 3 `weeksAfter` firstThursdayIn nov -- thanksgiving+      ] ++ catMaybes [+        weekendHolidayFrom (jan 1)  -- newYearsDay+      , weekendHolidayFrom (jan 20) -- inaugurationDay+      , weekendHolidayFrom (jul 4)  -- independenceDay+      , weekendHolidayFrom (nov 11) -- veteransDay+      , weekendHolidayFrom (dec 25) -- christmas+      ]++{- | whether the given day is a bank holiday -}+isBankHoliday :: Day -> Bool+isBankHoliday d = d `elem` (bankHolidays year)+  where+    (year,_,_) = toGregorian d++-- | day federal bank holidays were announced in the United States+-- | March 9th 1933+filterHistoric = filter (\d -> d > marchNinth1933)+  where marchNinth1933 = fromGregorian 1933 3 9++weekendHolidayFrom :: Day -> Maybe Day+weekendHolidayFrom d = case weekIndex d of+  3 -> Nothing            -- saturday+  4 -> Just (addDays 1 d) -- sunday+  _ -> Just d++-- | 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)+weeksBefore n = addDays (n * (-7))+weekBefore = weeksBefore 1+weeksAfter n = addDays (n * 7)+weekAfter = weeksAfter 1
+ LICENSE.md view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2015 brady.ouren <brady.ouren@gmail.com>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ README.md view
@@ -0,0 +1,40 @@+Holiday+---++[![Build Status](https://secure.travis-ci.org/tippenein/BankHoliday.png)](http://travis-ci.org/tippenein/BankHoliday)++A haskell library for holidays++----++- 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+- Memorial Day - Last Monday in May+- Independence Day - July 4+- Labor Day - First Monday in September+- Columbus Day - Second Monday in October+- Veterans Day - November 11+- Thanksgiving Day - 4th Thursday in November+- Christmas Day - December 25++> For holidays falling on Saturday, Federal Reserve Banks and Branches will be+  open the preceding Friday. For holidays falling on Sunday, all Federal+  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++# Test package.+stack test++```++Inspired by [this](https://hackage.haskell.org/package/bank-holidays-england)+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ bank-holiday-usa.cabal view
@@ -0,0 +1,48 @@+name: bank-holiday-usa+version: 0.0.1+cabal-version: >=1.10+build-type: Simple+license: MIT+license-file: LICENSE.md+homepage: https://github.com/tippenein/BankHoliday+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+description:+    A library for determining US bank holidays+category: Time+author: brady.ouren <brady.ouren@gmail.com>+tested-with: GHC ==7.8 GHC ==7.6+extra-source-files:+  README.md++library+  exposed-modules:+      Data.Time.Calendar.BankHoliday+    , Data.Time.Calendar.BankHoliday.UnitedStates+  build-depends:+      base ==4.*+    , time+  default-language: Haskell2010+  ghc-options: -Wall -fno-warn-missing-signatures++test-suite tests+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  build-depends:+      base -any+    , bank-holiday-usa -any+    , time+    , hspec ==2.*+    , HUnit -any+    , 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+  type:     git+  location: git://github.com/tippenein/BankHoliday.git
+ test/Data/Time/Calendar/BankHoliday/UnitedStatesSpec.hs view
@@ -0,0 +1,31 @@+{-# LANGUAGE OverloadedStrings #-}++module Data.Time.Calendar.BankHoliday.UnitedStatesSpec (spec) where++import Data.Time+import Test.Hspec+import Test.QuickCheck++import Data.Time.Calendar.BankHoliday (isWeekday)+import Data.Time.Calendar.BankHoliday.UnitedStates++spec :: Spec+spec = do+  describe "bankHolidays" $ do+    it "are always a weekday" $ property+      $ \yr -> all (\d -> isWeekday d) (bankHolidays yr)++    it "do not include dates before the inception of bank holidays" $ do+      (bankHolidays 1932) `shouldBe` []++    it "falling on a sunday are delegated to following monday" $ do+      (bankHolidays 2017) `shouldContain` [fromGregorian 2017 1 2]++    it "falling on a saturday are open the preceding friday" $ do+      (bankHolidays 2011) `shouldNotContain` [fromGregorian 2011 12 31]++  describe "isBankHoliday" $ do+    it "returns true for the days we expect" $ do+      let christmas = fromGregorian 2015 12 25+      isBankHoliday christmas `shouldBe` True+
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}