Remove year section
This commit is contained in:
parent
80b8003da4
commit
4be7709d9f
@ -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:
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user