fix(schedule-week): exclude day information from timeslot

This commit is contained in:
Sarah Vaupel 2020-08-21 17:38:37 +02:00
parent c0fb5adec0
commit 7c4dc0d6d6
2 changed files with 13 additions and 13 deletions

View File

@ -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)

View File

@ -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