From 7c4dc0d6d6f7b1606e384fa4ba9c3b4b3679499b Mon Sep 17 00:00:00 2001 From: Sarah Vaupel <> Date: Fri, 21 Aug 2020 17:38:37 +0200 Subject: [PATCH] fix(schedule-week): exclude day information from timeslot --- src/Utils/Schedule/Week.hs | 12 ++++++------ src/Utils/Schedule/Week/TimeSlot.hs | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Utils/Schedule/Week.hs b/src/Utils/Schedule/Week.hs index edfa62e4b..92e60de7b 100644 --- a/src/Utils/Schedule/Week.hs +++ b/src/Utils/Schedule/Week.hs @@ -113,15 +113,15 @@ weekSchedule uid _dayOffset = do in Just ScheduleEntry{..} examOccurrenceToScheduleEntry _ = Nothing -- TODO: exclude (_,_,Nothing) case via join - seOccurrenceIsInSlot :: TimeSlot -> ScheduleEntryOccurrence -> Bool - seOccurrenceIsInSlot timeSlot@(day,slot) = \case - Right occurrence -> occStart `isInTimeSlot` timeSlot where + 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) - Left ScheduleEntryExamOccurrence{..} -> let slotUTCTime = timeSlotToUTCTime tz timeSlot - nextSlotUTCTime = timeSlotToUTCTime tz (day,slot+slotStep) + Left ScheduleEntryExamOccurrence{..} -> let slotUTCTime = timeSlotToUTCTime tz day slot + nextSlotUTCTime = timeSlotToUTCTime tz day (slot+slotStep) in slotUTCTime <= seeoStart && seeoStart < nextSlotUTCTime @@ -130,7 +130,7 @@ weekSchedule uid _dayOffset = do ( day , Map.fromList $ slotsToDisplay <&> \slot -> ( slot - , filter (seOccurrenceIsInSlot (day,slot) . seOccurrence) $ join $ + , filter (seOccurrenceIsInSlot day slot . seOccurrence) $ join $ (courseEventToScheduleEntries <$> courseEvents) <> (tutorialToScheduleEntries <$> tutorials) <> (pure . catMaybes) (examOccurrenceToScheduleEntry <$> examOccurrences) diff --git a/src/Utils/Schedule/Week/TimeSlot.hs b/src/Utils/Schedule/Week/TimeSlot.hs index 53d9c9aed..595c6dc41 100644 --- a/src/Utils/Schedule/Week/TimeSlot.hs +++ b/src/Utils/Schedule/Week/TimeSlot.hs @@ -11,23 +11,23 @@ import Handler.Utils.DateTime (formatTimeRangeW) -- TODO: very temporary slot representation, WORK IN PROGRESS -- TODO: include UTCTime stamps for begin and end (end timestamp excluded) -type TimeSlot = (Day, Int) +type TimeSlot = Int -firstSlot, lastSlot, slotStep :: Int +firstSlot, lastSlot, slotStep :: TimeSlot firstSlot = 8 lastSlot = 18 slotStep = 2 -slotsToDisplay :: [Int] +slotsToDisplay :: [TimeSlot] slotsToDisplay = [firstSlot,firstSlot+slotStep..lastSlot] -isInTimeSlot :: (Day, TimeOfDay) -> TimeSlot -> Bool +isInTimeSlot :: (Day, TimeOfDay) -> (Day, TimeSlot) -> Bool isInTimeSlot (day,time) (slotDay,slotHour) = day == slotDay && TimeOfDay slotHour 0 0 <= time && time < TimeOfDay (slotHour+slotStep) 0 0 -- | Convert a TimeSlot to UTCTime for a given TimeZone -timeSlotToUTCTime :: TimeZone -> TimeSlot -> UTCTime -timeSlotToUTCTime tz (day,slot) = UTCTime{..} where +timeSlotToUTCTime :: TimeZone -> Day -> TimeSlot -> UTCTime +timeSlotToUTCTime tz day slot = UTCTime{..} where utctDay = slotDayOffset `addDays` day utctDayTime = timeOfDayToTime slotTimeOfDay (slotDayOffset, slotTimeOfDay) = localToUTCTimeOfDay tz $ TimeOfDay slot 0 0 @@ -35,5 +35,5 @@ timeSlotToUTCTime tz (day,slot) = UTCTime{..} where -- TODO: refactor in progress -- | Format a given TimeSlot t as time range from t until the next TimeSlot -formatTimeSlotW :: Int -> Widget +formatTimeSlotW :: TimeSlot -> Widget formatTimeSlotW slot = formatTimeRangeW SelFormatTime (TimeOfDay slot 0 0) $ Just $ TimeOfDay (slot+slotStep) 0 0