refactor(schedule-week): minor TimeSlot refactor

This commit is contained in:
Sarah Vaupel 2020-08-23 18:12:03 +02:00
parent 113f21fc29
commit 7856aba24d
2 changed files with 8 additions and 8 deletions

View File

@ -113,11 +113,11 @@ weekSchedule uid dayOffset = do
seOccurrenceIsInSlot :: Day -> TimeSlot -> ScheduleEntryOccurrence -> Bool
seOccurrenceIsInSlot day slot = \case
Right occurrence -> occStart `isInTimeSlot` (day, slot) where
occStart = case occurrence of
Right ScheduleWeekly{..} -> (scheduleDayOfWeek `dayOfWeekToDayWith` now, scheduleStart)
Left ExceptOccur{..} -> (exceptDay, exceptStart)
Left ExceptNoOccur{exceptTime=LocalTime{..}} -> (localDay, localTimeOfDay)
Right occurrence -> occDay == day && occTime `isInTimeSlot` slot where
(occDay,occTime) = case occurrence of
Right ScheduleWeekly{..} -> (scheduleDayOfWeek `dayOfWeekToDayWith` now, scheduleStart)
Left ExceptOccur{..} -> (exceptDay, exceptStart)
Left ExceptNoOccur{exceptTime=LocalTime{..}} -> (localDay, localTimeOfDay)
Left ScheduleEntryExamOccurrence{..} -> let slotUTCTime = timeSlotToUTCTime tz day slot
nextSlotUTCTime = timeSlotToUTCTime tz day (slot+slotStep)
in slotUTCTime <= seeoStart

View File

@ -21,9 +21,10 @@ slotStep = 2
slotsToDisplay :: [TimeSlot]
slotsToDisplay = [firstSlot,firstSlot+slotStep..lastSlot]
isInTimeSlot :: (Day, TimeOfDay) -> (Day, TimeSlot) -> Bool
isInTimeSlot (day,time) (slotDay,slotHour) = day == slotDay && TimeOfDay slotHour 0 0 <= time && time < TimeOfDay (slotHour+slotStep) 0 0
-- | Check whether a given time of day lies within a given time slot
isInTimeSlot :: TimeOfDay -> TimeSlot -> Bool
isInTimeSlot time slot = TimeOfDay slot 0 0 <= time && time < TimeOfDay (slot+slotStep) 0 0
-- | Convert a TimeSlot to UTCTime for a given TimeZone
timeSlotToUTCTime :: TimeZone -> Day -> TimeSlot -> UTCTime
@ -32,7 +33,6 @@ timeSlotToUTCTime tz day slot = UTCTime{..} where
utctDayTime = timeOfDayToTime slotTimeOfDay
(slotDayOffset, slotTimeOfDay) = localToUTCTimeOfDay tz $ TimeOfDay slot 0 0
-- TODO: refactor in progress
-- | Format a given TimeSlot t as time range from t until the next TimeSlot
formatTimeSlotW :: TimeSlot -> Widget