refactor(schedule-week): add small timslot convenience function

This commit is contained in:
Sarah Vaupel 2020-08-25 14:00:41 +02:00
parent 2428e5ec72
commit a651e3d62d
2 changed files with 7 additions and 2 deletions

View File

@ -119,10 +119,10 @@ weekSchedule uid dayOffset = do
-- TODO: make this configurable
timeSlotsDefaultDisplay :: Set TimeSlot
timeSlotsDefaultDisplay = Set.fromList $ timeSlot <$> [8,10..18]
timeSlotsDefaultDisplay = Set.fromList $ timeSlotsFromTo 8 18
allTimeSlots :: [TimeSlot]
allTimeSlots = timeSlot <$> [0,2..22]
allTimeSlots = timeSlotsFromTo 0 22
timeSlotIsEmpty :: TimeSlot -> Bool
timeSlotIsEmpty slot = foldr (\day acc -> acc && maybe True null (day Map.!? slot)) True events

View File

@ -1,6 +1,7 @@
module Utils.Schedule.Week.TimeSlot
( TimeSlot(..)
, timeSlot
, timeSlotsFromTo
, isInTimeSlot
, nextTimeSlot
, timeSlotToUTCTime
@ -28,6 +29,10 @@ timeSlot h = TimeSlot{..} where
tsTo = TimeOfDay (h+slotStep) 0 0
-- | Get TimeSlots from a given start TimeOfDay to a given end TimeOfDay
timeSlotsFromTo :: Int -> Int -> [TimeSlot]
timeSlotsFromTo f t = timeSlot <$> [f,f+slotStep..t]
-- | Check whether a given time of day lies within a given TimeSlot
isInTimeSlot :: TimeOfDay -> TimeSlot -> Bool
isInTimeSlot time TimeSlot{..} = tsFrom <= time && time < tsTo