cron 0.2.0 → 0.2.1
raw patch · 5 files changed
+22/−2 lines, 5 filesdep ~attoparsec
Dependency ranges changed: attoparsec
Files
- README.md +1/−0
- cron.cabal +2/−2
- src/System/Cron.hs +3/−0
- test/System/Cron/ParserSpec.hs +6/−0
- test/System/CronSpec.hs +10/−0
README.md view
@@ -34,3 +34,4 @@ ## Contributors * [Simon Hengel](https://github.com/sol)+* [Alberto Valverde](https://github.com/albertov)
cron.cabal view
@@ -1,5 +1,5 @@ Name: cron-Version: 0.2.0+Version: 0.2.1 Description: Cron data structure and Attoparsec parser. The idea is to embed it in larger systems which want to roll their own scheduled tasks in a format that people@@ -50,7 +50,7 @@ cron, hspec == 1.3.*, hspec-expectations,- attoparsec == 0.10.*,+ attoparsec >= 0.10, text >= 0.11 && < 2, time >= 1.4
src/System/Cron.hs view
@@ -200,6 +200,9 @@ -> CronField -> Bool matchField _ _ Star = True+matchField x CDayOfWeek (SpecificField y)+ | x == y || x == 0 && y == 7 || x == 7 && y == 0 = True+ | otherwise = False matchField x _ (SpecificField y) = x == y matchField x _ (RangeField y y') = x >= y && x <= y' matchField x unit (ListField fs) = any (matchField x unit) fs
test/System/Cron/ParserSpec.hs view
@@ -79,6 +79,12 @@ it "parses steps at the last field" $ assertSuccessfulParse "* * * * */4" stars { dayOfWeek = DaysOfWeek (StepField Star 4) }+ it "parses a sunday as 7" $+ assertSuccessfulParse "* * * * 7"+ stars { dayOfWeek = DaysOfWeek (SpecificField 7) }+ it "parses a sunday as 0" $+ assertSuccessfulParse "* * * * 0"+ stars { dayOfWeek = DaysOfWeek (SpecificField 0) } where assertSuccessfulParse = assertParse cronSchedule assertFailedParse = assertNoParse cronSchedule
test/System/CronSpec.hs view
@@ -57,6 +57,16 @@ dayOfMonth = DaysOfMonth (SpecificField 3), hour = Hours (RangeField 10 14) } (day 5 3 13 2)+ it "matches a monday as 1" $+ scheduleMatches stars { dayOfWeek = DaysOfWeek (SpecificField 1) }+ (UTCTime (fromGregorian 2014 3 17) 0)+ it "matches a sunday as 0" $+ scheduleMatches stars { dayOfWeek = DaysOfWeek (SpecificField 0) }+ (UTCTime (fromGregorian 2014 3 16) 0)+ it "matches a sunday as 7" $+ scheduleMatches stars { dayOfWeek = DaysOfWeek (SpecificField 7) }+ (UTCTime (fromGregorian 2014 3 16) 0)+ where day m d h mn = UTCTime (fromGregorian 2012 m d) (diffTime h mn) diffTime h mn = timeOfDayToTime $ TimeOfDay h mn 0