(reposRes, reposView) <- mreq (selectFieldList repolist) (bfs "") (Just ru)
(durationRes, durationView) <- mreq intField (bfs "") (Just $ durationSeconds d `quot` 60 )
(timeRes, timeView) <- mreq (selectFieldList times) (bfs "") (Just t)
- (recurranceRes, recurranceView) <- mreq (selectFieldList recurrances) (bfs "") (Just r)
+ (recurrenceRes, recurrenceView) <- mreq (selectFieldList recurrences) (bfs "") (Just r)
let form = do
webAppFormAuthToken
$(widgetFile "configurators/fsck/formcontent")
let formresult = mkFsck
<$> pure u
<*> reposRes
- <*> (Schedule <$> recurranceRes <*> timeRes)
+ <*> (Schedule <$> recurrenceRes <*> timeRes)
<*> (Duration <$> ((60 *) <$> durationRes))
return (formresult, form)
where
times = ensurevalue t (T.pack $ fromScheduledTime t) $
map (\x -> (T.pack $ fromScheduledTime x, x)) $
AnyTime : map (\h -> SpecificTime h 0) [0..23]
- recurrances :: [(Text, Recurrance)]
- recurrances = ensurevalue r (T.pack $ fromRecurrance r) $
+ recurrences :: [(Text, Recurrence)]
+ recurrences = ensurevalue r (T.pack $ fromRecurrence r) $
[ ("every day", Daily)
, ("every Sunday", Weekly $ Just 1)
, ("every Monday", Weekly $ Just 2)
module Utility.Scheduled (
Schedule(..),
- Recurrance(..),
+ Recurrence(..),
ScheduledTime(..),
NextTime(..),
WeekDay,
fromSchedule,
fromScheduledTime,
toScheduledTime,
- fromRecurrance,
- toRecurrance,
+ fromRecurrence,
+ toRecurrence,
toSchedule,
parseSchedule,
prop_past_sane,
import Prelude
{- Some sort of scheduled event. -}
-data Schedule = Schedule Recurrance ScheduledTime
+data Schedule = Schedule Recurrence ScheduledTime
deriving (Eq, Read, Show, Ord)
-data Recurrance
+data Recurrence
= Daily
| Weekly (Maybe WeekDay)
| Monthly (Maybe MonthDay)
| Yearly (Maybe YearDay)
- | Divisible Int Recurrance
+ | Divisible Int Recurrence
-- ^ Days, Weeks, or Months of the year evenly divisible by a number.
-- (Divisible Year is years evenly divisible by a number.)
deriving (Eq, Read, Show, Ord)
-- | Calculate the next time that fits a Schedule, based on the
-- last time it occurred, and the current time.
calcNextTime :: Schedule -> Maybe LocalTime -> LocalTime -> Maybe NextTime
-calcNextTime schedule@(Schedule recurrance scheduledtime) lasttime currenttime
+calcNextTime schedule@(Schedule recurrence scheduledtime) lasttime currenttime
| scheduledtime == AnyTime = do
next <- findfromtoday True
return $ case next of
NextTimeExactly t -> window (localDay t) (localDay t)
| otherwise = NextTimeExactly . startTime <$> findfromtoday False
where
- findfromtoday anytime = findfrom recurrance afterday today
+ findfromtoday anytime = findfrom recurrence afterday today
where
today = localDay currenttime
afterday = sameaslastrun || toolatetoday
maxwday :: Int
maxwday = 7
-fromRecurrance :: Recurrance -> String
-fromRecurrance (Divisible n r) =
- fromRecurrance' (++ "s divisible by " ++ show n) r
-fromRecurrance r = fromRecurrance' ("every " ++) r
+fromRecurrence :: Recurrence -> String
+fromRecurrence (Divisible n r) =
+ fromRecurrence' (++ "s divisible by " ++ show n) r
+fromRecurrence r = fromRecurrence' ("every " ++) r
-fromRecurrance' :: (String -> String) -> Recurrance -> String
-fromRecurrance' a Daily = a "day"
-fromRecurrance' a (Weekly n) = onday n (a "week")
-fromRecurrance' a (Monthly n) = onday n (a "month")
-fromRecurrance' a (Yearly n) = onday n (a "year")
-fromRecurrance' a (Divisible _n r) = fromRecurrance' a r -- not used
+fromRecurrence' :: (String -> String) -> Recurrence -> String
+fromRecurrence' a Daily = a "day"
+fromRecurrence' a (Weekly n) = onday n (a "week")
+fromRecurrence' a (Monthly n) = onday n (a "month")
+fromRecurrence' a (Yearly n) = onday n (a "year")
+fromRecurrence' a (Divisible _n r) = fromRecurrence' a r -- not used
onday :: Maybe Int -> String -> String
onday (Just n) s = "on day " ++ show n ++ " of " ++ s
onday Nothing s = s
-toRecurrance :: String -> Maybe Recurrance
-toRecurrance s = case words s of
+toRecurrence :: String -> Maybe Recurrence
+toRecurrence s = case words s of
("every":"day":[]) -> Just Daily
("on":"day":sd:"of":"every":something:[]) -> withday sd something
("every":something:[]) -> noday something
<*> if null m then Just 0 else readish m
fromSchedule :: Schedule -> String
-fromSchedule (Schedule recurrance scheduledtime) = unwords
- [ fromRecurrance recurrance
+fromSchedule (Schedule recurrence scheduledtime) = unwords
+ [ fromRecurrence recurrence
, "at"
, fromScheduledTime scheduledtime
]
parseSchedule :: String -> Either String Schedule
parseSchedule s = do
- r <- maybe (Left $ "bad recurrance: " ++ recurrance) Right
- (toRecurrance recurrance)
+ r <- maybe (Left $ "bad recurrence: " ++ recurrence) Right
+ (toRecurrence recurrence)
t <- maybe (Left $ "bad time of day: " ++ scheduledtime) Right
(toScheduledTime scheduledtime)
Right $ Schedule r t
where
(rws, tws) = separate (== "at") (words s)
- recurrance = unwords rws
+ recurrence = unwords rws
scheduledtime = unwords tws
prop_past_sane :: Bool