refactor(schedule-week): move TimeSlot to separate module
This commit is contained in:
parent
d82c6b073f
commit
db49943baf
@ -17,26 +17,7 @@ import Handler.Utils.DateTime (formatTimeRangeW, formatTimeW)
|
||||
import Utils.Course (mayViewCourse, isCourseLecturer)
|
||||
|
||||
import Utils.Schedule.Types
|
||||
|
||||
|
||||
-- TODO: very temporary slot representation
|
||||
type TimeSlot = Int
|
||||
firstSlot, lastSlot, slotStep :: Int
|
||||
firstSlot = 8
|
||||
lastSlot = 18
|
||||
slotStep = 2
|
||||
|
||||
slotsToDisplay :: [TimeSlot]
|
||||
slotsToDisplay = [firstSlot,firstSlot+slotStep..lastSlot]
|
||||
|
||||
timeSlotToUTCTime :: Day -> TimeSlot -> TimeZone -> UTCTime
|
||||
timeSlotToUTCTime day slot tz = UTCTime{..} where
|
||||
utctDay = slotDayOffset `addDays` day
|
||||
utctDayTime = timeOfDayToTime slotTimeOfDay
|
||||
(slotDayOffset, slotTimeOfDay) = localToUTCTimeOfDay tz $ TimeOfDay slot 0 0
|
||||
|
||||
slotToDisplayTime :: TimeSlot -> Widget
|
||||
slotToDisplayTime t = formatTimeRangeW SelFormatTime (TimeOfDay t 0 0) $ Just $ TimeOfDay (t + slotStep) 0 0
|
||||
import Utils.Schedule.Week.TimeSlot
|
||||
|
||||
|
||||
-- TODO: implement weekOffset
|
||||
@ -145,8 +126,8 @@ weekSchedule uid _weekOffset = do
|
||||
-> day == localDay
|
||||
&& TimeOfDay slot 0 0 <= localTimeOfDay
|
||||
&& localTimeOfDay < TimeOfDay (slot+slotStep) 0 0
|
||||
Left ScheduleEntryExamOccurrence{..} -> let slotUTCTime = timeSlotToUTCTime day slot tz
|
||||
nextSlotUTCTime = timeSlotToUTCTime day (slot+slotStep) tz
|
||||
Left ScheduleEntryExamOccurrence{..} -> let slotUTCTime = timeSlotToUTCTime tz day slot
|
||||
nextSlotUTCTime = timeSlotToUTCTime tz day (slot+slotStep)
|
||||
in slotUTCTime <= seeoStart
|
||||
&& seeoStart < nextSlotUTCTime
|
||||
|
||||
|
||||
35
src/Utils/Schedule/Week/TimeSlot.hs
Normal file
35
src/Utils/Schedule/Week/TimeSlot.hs
Normal file
@ -0,0 +1,35 @@
|
||||
module Utils.Schedule.Week.TimeSlot
|
||||
( TimeSlot, firstSlot, lastSlot, slotStep, slotsToDisplay
|
||||
, timeSlotToUTCTime
|
||||
, formatTimeSlotW
|
||||
) where
|
||||
|
||||
import Import
|
||||
|
||||
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 = Int
|
||||
|
||||
firstSlot, lastSlot, slotStep :: TimeSlot
|
||||
firstSlot = 8
|
||||
lastSlot = 18
|
||||
slotStep = 2
|
||||
|
||||
slotsToDisplay :: [TimeSlot]
|
||||
slotsToDisplay = enumFromThenTo firstSlot slotStep lastSlot
|
||||
|
||||
|
||||
-- | Convert a TimeSlot to UTCTime for a given TimeZone and Day
|
||||
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
|
||||
|
||||
|
||||
-- | Format a given TimeSlot t as time range from t until the next TimeSlot
|
||||
formatTimeSlotW :: TimeSlot -> Widget
|
||||
formatTimeSlotW slot = formatTimeRangeW SelFormatTime (TimeOfDay slot 0 0) $ Just $ TimeOfDay (slot+slotStep) 0 0
|
||||
@ -12,7 +12,7 @@ $newline never
|
||||
$forall slot <- slotsToDisplay
|
||||
<tr .table__row>
|
||||
<td .table__td>
|
||||
^{slotToDisplayTime slot}
|
||||
^{formatTimeSlotW slot}
|
||||
$forall (day, _, _) <- weekDays
|
||||
<td .table__td>
|
||||
<div .table__td-content>
|
||||
|
||||
Reference in New Issue
Block a user