usa-holidays (empty) → 0.1.0.0
raw patch · 8 files changed
+221/−0 lines, 8 filesdep +basedep +doctestdep +doctest-discoversetup-changed
Dependencies added: base, doctest, doctest-discover, hspec, time, usa-holidays
Files
- LICENSE +30/−0
- README.md +12/−0
- Setup.hs +2/−0
- doctest-driver.hs +1/−0
- src/Data/Holiday/USA.hs +78/−0
- test/Data/Holiday/USASpec.hs +28/−0
- test/Spec.hs +1/−0
- usa-holidays.cabal +69/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2019++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Author name here nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,12 @@+# usa-holidays++[](https://travis-ci.com/kkweon/usa-holidays)++USA Holidays library in Haskell.++## Getting Started++```haskell+let christmas = Time.fromGregorian 2019 12 25+USA.getHoliday christmas `shouldBe` Just (USA.Holiday christmas "Christmas")+```
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ doctest-driver.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF doctest-discover #-}
+ src/Data/Holiday/USA.hs view
@@ -0,0 +1,78 @@+module Data.Holiday.USA+ ( Holiday(Holiday)+ , getHoliday+ ) where++import qualified Data.Time as Time+import qualified Data.Time.Calendar.WeekDate as Time++-- | Holiday means a "real" holiday day like you may not go to work on that day.+-- Like Mother's day isn't considered a holiday because it's on Sundays.+data Holiday =+ Holiday+ { holiday_day :: Time.Day -- ^ The actual day of the holiday+ , holiday_name :: String -- ^ The name of the holiday according to Wikipedia+ }+ deriving (Eq, Show)++-- | Returns a Holiday if the given date is+--+-- Examples:+--+-- >>> let christmas = Time.fromGregorian 2019 12 25+-- >>> getHoliday christmas+-- Just (Holiday {holiday_day = 2019-12-25, holiday_name = "Christmas"})+--+-- >>> let noHoliday = Time.fromGregorian 2019 12 20+-- >>> getHoliday noHoliday+-- Nothing+getHoliday :: Time.Day -> Maybe Holiday+getHoliday d+ | isChristmas d = Just (Holiday d "Christmas")+ | isThanksgiving d = Just (Holiday d "Thanksgiving")+ | isIndependence d = Just (Holiday d "Independence Day")+ | isNewYearsEve d = Just (Holiday d "New Year's Eve")+ | isMemorialDay d = Just (Holiday d "Memorial Day")+ | isLaborDay d = Just (Holiday d "Labor Day")+ | otherwise = Nothing+ where+ isChristmas :: Time.Day -> Bool+ isChristmas _d =+ let (_, month, day) = Time.toGregorian _d+ in month == 12 && day == 25+ isThanksgiving :: Time.Day -> Bool+ isThanksgiving _d =+ let (_, month, day) = Time.toGregorian _d+ in month == 11 && 22 <= day && day <= 28 && getDayOfWeek _d == Thursday+ isIndependence :: Time.Day -> Bool+ isIndependence _d =+ let (_, month, day) = Time.toGregorian _d+ in month == 7 && day == 4+ isNewYearsEve :: Time.Day -> Bool+ isNewYearsEve _d =+ let (_, month, day) = Time.toGregorian _d+ in month == 12 && day == 31+ isMemorialDay _d =+ let (_, month, day) = Time.toGregorian _d+ in month == 5 && 25 <= day && day <= 31 && getDayOfWeek _d == Monday+ isLaborDay _d =+ let (_, month, day) = Time.toGregorian _d+ in month == 9 && 1 <= day && day <= 7 && getDayOfWeek _d == Monday++++data DayOfWeek+ = Monday+ | Tuesday+ | Wednesday+ | Thursday+ | Friday+ | Saturday+ | Sunday+ deriving (Enum, Eq, Show)++-- | This should be removed when 'time' package has been updated to 1.9.3++getDayOfWeek :: Time.Day -> DayOfWeek+getDayOfWeek d =+ let (_, _, dow) = Time.toWeekDate d+ in toEnum (dow - 1)
+ test/Data/Holiday/USASpec.hs view
@@ -0,0 +1,28 @@+module Data.Holiday.USASpec where++import Test.Hspec++import qualified Data.Holiday.USA as USA+import qualified Data.Time as Time++spec :: Spec+spec =+ describe "Data.Holiday.USASpec" $ do+ it "returns Christmas on 2019/12/25" $ do+ let christmas = Time.fromGregorian 2019 12 25+ USA.getHoliday christmas `shouldBe` Just (USA.Holiday christmas "Christmas")+ it "returns Thanksgiving on 2019/11/28" $ do+ let thanksgiving = Time.fromGregorian 2019 11 28+ USA.getHoliday thanksgiving `shouldBe` Just (USA.Holiday thanksgiving "Thanksgiving")+ it "returns Independence Day on 2019/07/4" $ do+ let independence = Time.fromGregorian 2019 7 4+ USA.getHoliday independence `shouldBe` Just (USA.Holiday independence "Independence Day")+ it "returns New Year's Eve on 2019/1/1" $ do+ let newYear = Time.fromGregorian 2019 12 31+ USA.getHoliday newYear `shouldBe` Just (USA.Holiday newYear "New Year's Eve")+ it "returns Memorial Day on 2019/5/27" $ do+ let memorialDay = Time.fromGregorian 2019 5 27+ USA.getHoliday memorialDay `shouldBe` Just (USA.Holiday memorialDay "Memorial Day")+ it "returns Labor Day on 2019/9/2" $ do+ let laborDay = Time.fromGregorian 2019 9 2+ USA.getHoliday laborDay `shouldBe` Just (USA.Holiday laborDay "Labor Day")
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
+ usa-holidays.cabal view
@@ -0,0 +1,69 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: e6a45e2c80f5102b5f8fe35fbab4ee66904e7767a54b4aa54bc8a2699c2d20fd++name: usa-holidays+version: 0.1.0.0+description: Please see the README on GitHub at <https://github.com/kkweon/usa-holidays#readme>+homepage: https://github.com/kkweon/usa-holidays#readme+bug-reports: https://github.com/kkweon/usa-holidays/issues+author: Kyung Mo Kweon+maintainer: kkweon@gmail.com+copyright: 2019 Kyung Mo Kweon+license: BSD3+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md++source-repository head+ type: git+ location: https://github.com/kkweon/usa-holidays++library+ exposed-modules:+ Data.Holiday.USA+ other-modules:+ Paths_usa_holidays+ hs-source-dirs:+ src+ build-depends:+ base >=4.7 && <5+ , time+ default-language: Haskell2010++test-suite usa-holidays-dodctest+ type: exitcode-stdio-1.0+ main-is: doctest-driver.hs+ other-modules:+ Paths_usa_holidays+ hs-source-dirs:+ ./.+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ base >=4.7 && <5+ , doctest+ , doctest-discover+ , time+ , usa-holidays+ default-language: Haskell2010++test-suite usa-holidays-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Data.Holiday.USASpec+ Paths_usa_holidays+ hs-source-dirs:+ test+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ base >=4.7 && <5+ , hspec+ , time+ , usa-holidays+ default-language: Haskell2010