From 00a08d0fbe7295d1e815bca4d2c85ac064caf97e Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sun, 29 Jan 2023 10:51:03 -0500 Subject: [PATCH] ENH remove last two digit year check --- lib/Internal/Insert.hs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/Internal/Insert.hs b/lib/Internal/Insert.hs index bbf584e..199ebcb 100644 --- a/lib/Internal/Insert.hs +++ b/lib/Internal/Insert.hs @@ -57,11 +57,10 @@ cronPatternMatches yMaybe (y' - 2000) y && mdMaybe m' m && mdMaybe d' d && wdMaybe (dayOfWeek_ x) w where testMaybe = maybe True - yMaybe z = testMaybe (mdyPatternMatches testYear (fromIntegral z)) - mdMaybe z = testMaybe (mdyPatternMatches (const Nothing) (fromIntegral z)) + yMaybe z = testMaybe (mdyPatternMatches (fromIntegral z)) + mdMaybe z = testMaybe (mdyPatternMatches (fromIntegral z)) wdMaybe z = testMaybe (`weekdayPatternMatches` z) (y', m', d') = toGregorian x - testYear z = if z > 99 then Just "year must be 2 digits" else Nothing dayOfWeek_ :: Day -> Weekday dayOfWeek_ d = case dayOfWeek d of @@ -77,16 +76,12 @@ weekdayPatternMatches :: WeekdayPat -> Weekday -> Bool weekdayPatternMatches (OnDay x) = (== x) weekdayPatternMatches (OnDays xs) = (`elem` xs) -mdyPatternMatches :: (Natural -> Maybe String) -> Natural -> MDYPat -> Bool -mdyPatternMatches check x p = case p of - Single y -> errMaybe (check y) $ x == y - Multi xs -> errMaybe (msum $ check <$> xs) $ x `elem` xs +mdyPatternMatches :: Natural -> MDYPat -> Bool +mdyPatternMatches x p = case p of + Single y -> x == y + Multi xs -> x `elem` xs Repeat (RepeatPat {rpStart = s, rpBy = b, rpRepeats = r}) -> - errMaybe (check s) $ - s >= x && mod x b == 0 && maybe True (\y -> x <= s + b * y) r - where - errMaybe test rest = maybe rest err test - err msg = error $ show p ++ ": " ++ msg + s >= x && mod x b == 0 && maybe True (\y -> x <= s + b * y) r -------------------------------------------------------------------------------- -- budget