aboutsummaryrefslogtreecommitdiff
path: root/Utility/Scheduled.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-04-11 21:42:43 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-04-11 21:42:43 -0400
commitb8b328f962b81f26d91da4da918a461677af0eaa (patch)
tree1f066864ce37e912bd9ae8e14334e3a94085e266 /Utility/Scheduled.hs
parentdc2f80d106b1abca527048f42f1e4acc866e2d84 (diff)
Improve handling on monthly/yearly scheduling.
Code was still buggy, it turns out (though the recursion checker caught it). In the case of (Schedule (Monthly Nothing) AnyTime), where the last run was on yyyy-12-31, it looped forever. Also, the handling of (Schedule (Yearly Nothing) AnyTime) was wacky where the last run was yyyy-12-31. It would suggest a window starting on the 3rd for the next run (because 31 mod 28 is 3). I think that originally I was wanted to avoid running on 01-01 if it had just run on 12-31. But the code didn't accomplish this, and it's not necessary anyway. This is supposed to calculate the next window meeting the schedule, and for (Schedule (Monthly Nothing), the window starts at 01-01 and runs through 01-31. If that causes two back-to-back runs, well the next one will not be until 02-01 at the earliest. Also, back-to-back runs can be avoided, if desired, by using Divisible 2.
Diffstat (limited to 'Utility/Scheduled.hs')
-rw-r--r--Utility/Scheduled.hs17
1 files changed, 7 insertions, 10 deletions
diff --git a/Utility/Scheduled.hs b/Utility/Scheduled.hs
index 1b25cb4c7..4dfa4d04c 100644
--- a/Utility/Scheduled.hs
+++ b/Utility/Scheduled.hs
@@ -14,6 +14,7 @@ module Utility.Scheduled (
MonthDay,
YearDay,
nextTime,
+ calcNextTime,
startTime,
fromSchedule,
fromScheduledTime,
@@ -22,7 +23,7 @@ module Utility.Scheduled (
toRecurrance,
toSchedule,
parseSchedule,
- prop_schedule_roundtrips
+ prop_schedule_roundtrips,
) where
import Utility.Data
@@ -127,14 +128,14 @@ calcNextTime schedule@(Schedule recurrance scheduledtime) lasttime currenttime
| otherwise -> skip 1
Monthly Nothing
| afterday -> skip 1
- | maybe True (\old -> mday candidate > mday old && mday candidate >= (mday old `mod` minmday)) lastday ->
- -- Window only covers current month,
- -- in case there is a Divisible requirement.
+ -- any day in the month following lasttime
+ | maybe True (\old -> (mnum candidate > mnum old || ynum candidate > ynum old)) lastday ->
Just $ window candidate (endOfMonth candidate)
| otherwise -> skip 1
Yearly Nothing
| afterday -> skip 1
- | maybe True (\old -> ynum candidate > ynum old && yday candidate >= (yday old `mod` minyday)) lastday ->
+ -- any day in the year following lasttime
+ | maybe True (\old -> ynum candidate > ynum old) lastday ->
Just $ window candidate (endOfYear candidate)
| otherwise -> skip 1
Weekly (Just w)
@@ -200,17 +201,13 @@ yday = snd . toOrdinalDate
ynum :: Day -> Int
ynum = fromIntegral . fst . toOrdinalDate
-{- Calendar max and mins. -}
+{- Calendar max values. -}
maxyday :: Int
maxyday = 366 -- with leap days
-minyday :: Int
-minyday = 365
maxwnum :: Int
maxwnum = 53 -- some years have more than 52
maxmday :: Int
maxmday = 31
-minmday :: Int
-minmday = 28
maxmnum :: Int
maxmnum = 12
maxwday :: Int