refactor(schedule-week): add small timslot convenience function
This commit is contained in:
parent
2428e5ec72
commit
a651e3d62d
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user