Skip to content

Commit 73b7a9e

Browse files
committed
Schedule parsing errors, fix timezone bug
Timezone is properly converted!
1 parent 618e236 commit 73b7a9e

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

BrickHack-Mobile/AlertMessage.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,11 @@ class MessageHandler {
117117
body: "Setting a placeholder name in the meantime...",
118118
type: .info)
119119
}
120+
121+
static func showScheduleParsingError() {
122+
print("ERROR: Unable to get latest schedule")
123+
showAlertMessage(withTitle: "Unable to get latest schedule!",
124+
body: "Please try again later, by restarting the app.",
125+
type: .error)
126+
}
120127
}

BrickHack-Mobile/Models/ScheduleParser.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct Event: CustomDebugStringConvertible {
2929
var timeString: String {
3030
let dateFormatter = DateFormatter()
3131
dateFormatter.dateFormat = "E hh:mm a"
32-
dateFormatter.timeZone = TimeZone(identifier: "UTC") // Already in ET, dont convert again
32+
dateFormatter.timeZone = TimeZone(identifier: "America/New_York")
3333
return dateFormatter.string(from: time)
3434
}
3535
var title: String
@@ -152,13 +152,17 @@ class ScheduleParser {
152152
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
153153

154154
guard error == nil else {
155-
// @TODO: Error handle
155+
DispatchQueue.main.async {
156+
MessageHandler.showScheduleParsingError()
157+
}
156158
print(error!)
157159
return
158160
}
159161

160162
guard let data = data else {
161-
// @TODO: Error handle
163+
DispatchQueue.main.async {
164+
MessageHandler.showScheduleParsingError()
165+
}
162166
print("no data")
163167
return
164168
}
@@ -175,7 +179,9 @@ class ScheduleParser {
175179

176180
} catch let error {
177181
// @TODO: Error handle (JSON parse error)
178-
print("it broke")
182+
DispatchQueue.main.async {
183+
MessageHandler.showScheduleParsingError()
184+
}
179185
print(error)
180186
}
181187
}
@@ -296,7 +302,7 @@ class ScheduleParser {
296302

297303
// Build the final date
298304
var dateComponents = DateComponents()
299-
dateComponents.timeZone = TimeZone(identifier: "America/New_York") // Might not be req'd but works
305+
dateComponents.timeZone = TimeZone(identifier: "America/New_York")
300306
dateComponents.year = 2020
301307
dateComponents.month = 2
302308
dateComponents.hour = Calendar.current.component(.hour, from: convertedTime!)

0 commit comments

Comments
 (0)