From 4be7709d9ff7bff04a7f20eba85fe26ec7292cf9 Mon Sep 17 00:00:00 2001 From: Anton Vakhrushev Date: Sat, 18 Nov 2017 12:36:10 +0300 Subject: [PATCH] Remove year section --- README.md | 2 +- src/Pattern.hs | 6 +----- test/PatternSpec.hs | 8 ++++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c590902..c4c2dbd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Match current time with given cron pattern. - $ haskell-cron-matcher "10-20 * * * * *" + $ haskell-cron-matcher "10-20 * * * *" See return code for result: diff --git a/src/Pattern.hs b/src/Pattern.hs index 7c3dc6d..2711021 100644 --- a/src/Pattern.hs +++ b/src/Pattern.hs @@ -16,7 +16,6 @@ data Pattern = Pattern , cday :: Field , cmonth :: Field , cweek :: Field - , cyear :: Field } deriving (Show) match :: String -> DateTime -> Maybe Bool @@ -39,12 +38,11 @@ parse text , cday = xs !! 2 , cmonth = xs !! 3 , cweek = xs !! 4 - , cyear = xs !! 5 } checkFields :: [Maybe Field] -> Bool checkFields xs - | length xs /= 6 = False + | length xs /= 5 = False | any isNothing xs = False | otherwise = True @@ -55,7 +53,6 @@ constraints = , Constraint 1 31 , Constraint 1 12 , Constraint 1 7 - , Constraint 0 9999 ] check :: Pattern -> DateTime -> Bool @@ -67,6 +64,5 @@ check ptn date = all isRight pairs , (cday ptn, day date) , (cmonth ptn, month date) , (cweek ptn, weekdayNumber $ dateWeekDay date) - , (cyear ptn, year date) ] isRight (p, value) = matchField p value diff --git a/test/PatternSpec.hs b/test/PatternSpec.hs index a0de050..85da8c2 100644 --- a/test/PatternSpec.hs +++ b/test/PatternSpec.hs @@ -15,20 +15,20 @@ spec :: Spec spec = describe "Cron pattern" $ do it "matches fixed time" $ - let ptn = "* * * * * *" + let ptn = "* * * * *" date = DateTime 2017 10 11 0 0 0 in match ptn date `shouldBe` Just True it "matches all minutes" $ - let ptn = "* * * * * *" + let ptn = "* * * * *" dates = [DateTime 2017 10 11 0 i 0 | i <- [0 .. 59]] in countMatches ptn dates `shouldBe` 60 it "matches exactly moment" $ let date = DateTime 2017 10 11 0 0 0 - ptn = "0 0 11 10 * 2017" + ptn = "0 0 11 10 *" in match ptn date `shouldBe` Just True it "matches moment" $ let date = DateTime 2017 10 10 12 10 0 - ptn = "* 12 * * * *" + ptn = "* 12 * * *" in match ptn date `shouldBe` Just True countMatches :: String -> [DateTime] -> Int