@@ -27,6 +27,7 @@ import Text.Blaze ((!))
27
27
import qualified Text.Blaze.Html5 as H
28
28
import qualified Text.Blaze.Html5.Attributes as A
29
29
import Text.Read (readMaybe )
30
+ import Util.Helpers
30
31
31
32
gridResponse :: ServerPart Response
32
33
gridResponse =
@@ -132,12 +133,15 @@ getCoursesInfo courses = map courseInfo allCourses
132
133
allCourses = map (T. splitOn " -" ) (T. splitOn " _" courses)
133
134
134
135
-- | Pulls either a Lecture, Tutorial or Pratical from the database.
135
- pullDatabase :: (Code , Section , Session ) -> IO MeetTime'
136
+ pullDatabase :: (Code , Section , Session ) -> IO ( Maybe MeetTime' )
136
137
pullDatabase (code, section, session) = runDb $ do
137
138
meet <- returnMeeting code fullSection session
138
- allTimes <- selectList [TimesMeeting ==. entityKey meet] []
139
- parsedTime <- mapM (buildTime . entityVal) allTimes
140
- return $ MeetTime' (entityVal meet) parsedTime
139
+ case meet of
140
+ Nothing -> return Nothing
141
+ Just x -> do
142
+ allTimes <- selectList [TimesMeeting ==. entityKey x] []
143
+ parsedTime <- mapM (buildTime . entityVal) allTimes
144
+ return $ Just (MeetTime' (entityVal x) parsedTime)
141
145
where
142
146
fullSection
143
147
| T. isPrefixOf " L" section = T. append " LEC" sectCode
@@ -150,9 +154,10 @@ pullDatabase (code, section, session) = runDb $ do
150
154
type SystemTime = String
151
155
152
156
-- | Creates all the events for a course.
153
- getEvents :: SystemTime -> MeetTime' -> IO [String ]
154
- getEvents systemTime lect = do
155
- courseInfo <- getCourseInfo lect -- Get the course information
157
+ getEvents :: SystemTime -> Maybe MeetTime' -> IO [String ]
158
+ getEvents _ Nothing = return []
159
+ getEvents systemTime (Just courseTime) = do
160
+ courseInfo <- getCourseInfo courseTime -- Get the course information
156
161
let startTimes = third courseInfo -- Extract start times
157
162
endTimes = fourth courseInfo -- Extract end times
158
163
dates = fifth courseInfo -- Extract dates
@@ -290,7 +295,7 @@ formatTimes fullTime =
290
295
else hour ++ maybe " 0000" formatMinutes minutes ++ " 00"
291
296
where
292
297
hours = splitOn " ." (show fullTime)
293
- hour = head hours
298
+ hour = safeHead " " hours
294
299
minutes = readMaybe $ hours !! 1
295
300
296
301
-- | The string representaion for minutes.
@@ -324,15 +329,17 @@ type EndDate = String
324
329
-- | Gives the appropriate starting and ending dates for each day, in which the
325
330
-- course takes place, depending on the course session.
326
331
getDatesByDay :: Session -> [Time ] -> IO (StartDate , EndDate )
327
- getDatesByDay session dataByDay
332
+ getDatesByDay _ [] = error " Failed to fetch dates"
333
+ getDatesByDay session (firstDate: _)
328
334
| session == " F" = do
329
335
fallStart <- fallStartDate
330
336
fallEnd <- fallEndDate
331
- formatDates $ getDates fallStart fallEnd (weekDay $ head dataByDay)
337
+ formatDates $ getDates fallStart fallEnd dayOfWeek
332
338
| otherwise = do
333
339
winterStart <- winterStartDate
334
340
winterEnd <- winterEndDate
335
- formatDates $ getDates winterStart winterEnd (weekDay $ head dataByDay)
341
+ formatDates $ getDates winterStart winterEnd dayOfWeek
342
+ where dayOfWeek = weekDay firstDate
336
343
337
344
-- | Formats the date in the following way: YearMonthDayT.
338
345
-- For instance, 20150720T corresponds to July 20th, 2015.
0 commit comments