refactor(schedule-week): minor TimeSlot refactor

This commit is contained in:
Sarah Vaupel 2020-08-24 22:43:29 +02:00
parent a025e57817
commit 78de1d56ae
2 changed files with 8 additions and 7 deletions

View File

@ -87,8 +87,7 @@ weekSchedule uid dayOffset = do
in \case
ScheduleCourseEvent{sceOccurrence} -> occurrenceIsInSlot sceOccurrence
ScheduleTutorial{stOccurrence} -> occurrenceIsInSlot stOccurrence
ScheduleExamOccurrence{seoStart} -> let slotTime = timeSlotToUTCTime tz day slot
nextSlotTime = timeSlotToUTCTime tz day $ nextTimeSlot slot
ScheduleExamOccurrence{seoStart} -> let (slotTime,nextSlotTime) = timeSlotToUTCTime tz day slot
in slotTime <= seoStart
&& seoStart < nextSlotTime

View File

@ -37,11 +37,13 @@ nextTimeSlot :: TimeSlot -> TimeSlot
nextTimeSlot 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
timeSlotToUTCTime tz day TimeSlot{..} = UTCTime{..} where
utctDay = slotDayOffset `addDays` day
utctDayTime = timeOfDayToTime slotTimeOfDay
(slotDayOffset, slotTimeOfDay) = localToUTCTimeOfDay tz tsFrom
timeSlotToUTCTime :: TimeZone -> Day -> TimeSlot -> (UTCTime, UTCTime)
timeSlotToUTCTime tz day TimeSlot{..} = (timeOfDayToUTC tsFrom, timeOfDayToUTC tsTo) where
timeOfDayToUTC time =
let (slotDayOffset, slotTimeOfDay) = localToUTCTimeOfDay tz time
utctDay = slotDayOffset `addDays` day
utctDayTime = timeOfDayToTime slotTimeOfDay
in UTCTime{..}
-- | Format a given TimeSlot as time range
formatTimeSlotW :: TimeSlot -> Widget