feat(schedule-week): use user timeslot settings
TODO/FIXME: timeslot handling needs major cleanup
This commit is contained in:
parent
6aaa5cc477
commit
4f13bd422c
@ -19,7 +19,7 @@ import Utils.Schedule.Week.TimeSlot
|
||||
|
||||
|
||||
weekSchedule :: Entity User -> ScheduleOffset -> Widget
|
||||
weekSchedule (Entity uid User{userWeekStart}) scheduleOffset = do
|
||||
weekSchedule (Entity uid User{..}) scheduleOffset = do
|
||||
now <- liftIO getCurrentTime
|
||||
tz <- liftIO getCurrentTimeZone
|
||||
ata <- getSessionActiveAuthTags
|
||||
@ -120,12 +120,12 @@ weekSchedule (Entity uid User{userWeekStart}) scheduleOffset = do
|
||||
| otherwise = go $ pred d
|
||||
firstDay = toEnum $ fromEnum userWeekStart + dayOffset
|
||||
|
||||
-- TODO: make this configurable
|
||||
-- TODO: avoid overlaps wrt. timeslot length (FIXME!!)
|
||||
timeSlotsDefaultDisplay :: Set TimeSlot
|
||||
timeSlotsDefaultDisplay = Set.fromList $ timeSlotsFromTo 8 18
|
||||
timeSlotsDefaultDisplay = Set.fromList $ timeSlotsFromTo userScheduleWeekTimeslotLength userScheduleWeekTimeFrom userScheduleWeekTimeTo
|
||||
|
||||
allTimeSlots :: [TimeSlot]
|
||||
allTimeSlots = timeSlotsFromTo 0 22
|
||||
allTimeSlots = timeSlotsFromTo userScheduleWeekTimeslotLength 0 (24 - userScheduleWeekTimeslotLength)
|
||||
|
||||
timeSlotIsEmpty :: TimeSlot -> Bool
|
||||
timeSlotIsEmpty slot = foldr (\d acc -> acc && maybe True null (d Map.!? slot)) True events
|
||||
|
||||
@ -15,27 +15,31 @@ import Handler.Utils.DateTime (formatTimeRangeW)
|
||||
import Utils.Schedule.Week.Types.TimeSlot
|
||||
|
||||
|
||||
slotStep :: Int
|
||||
slotStep = 2
|
||||
-- TODO: This module needs major refactoring
|
||||
|
||||
|
||||
timeSlot :: Int -> TimeSlot
|
||||
timeSlot h = TimeSlot{..} where
|
||||
-- TODO: remove (deprecated; now in user settings)
|
||||
-- slotStep :: Int
|
||||
-- slotStep = 2
|
||||
|
||||
|
||||
timeSlot :: Int -> Int -> TimeSlot
|
||||
timeSlot slotStep h = TimeSlot{..} where
|
||||
tsFrom = TimeOfDay h 0 0
|
||||
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]
|
||||
timeSlotsFromTo :: Int -> Int -> Int -> [TimeSlot]
|
||||
timeSlotsFromTo slotStep f t = (timeSlot slotStep) <$> [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
|
||||
|
||||
-- | Get the successor of a TimeSlot
|
||||
nextTimeSlot :: TimeSlot -> TimeSlot
|
||||
nextTimeSlot TimeSlot{tsTo=tsFrom} = let tsTo = TimeOfDay (todHour tsFrom + slotStep) 0 0 in TimeSlot{..}
|
||||
nextTimeSlot :: Int -> TimeSlot -> TimeSlot
|
||||
nextTimeSlot slotStep TimeSlot{tsTo=tsFrom} = let tsTo = TimeOfDay (todHour tsFrom + slotStep) 0 0 in TimeSlot{..}
|
||||
|
||||
-- | Convert a TimeSlot to UTCTime for a given TimeZone
|
||||
timeSlotToUTCTime :: TimeZone -> Day -> TimeSlot -> (UTCTime, UTCTime)
|
||||
|
||||
Reference in New Issue
Block a user