40 lines
1.3 KiB
Haskell
40 lines
1.3 KiB
Haskell
module Utils.Schedule.Week.TimeSlot
|
|
( TimeSlot, firstSlot, lastSlot, slotStep, slotsToDisplay, isInTimeSlot
|
|
, 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 = [firstSlot,firstSlot+slotStep..lastSlot]
|
|
|
|
|
|
-- | 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
|
|
timeSlotToUTCTime tz day slot = UTCTime{..} where
|
|
utctDay = slotDayOffset `addDays` day
|
|
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
|
|
formatTimeSlotW slot = formatTimeRangeW SelFormatTime (TimeOfDay slot 0 0) $ Just $ TimeOfDay (slot+slotStep) 0 0
|