This repository has been archived by the owner on Jan 19, 2018. It is now read-only.
/
DZCLabStatusHelper.m
92 lines (85 loc) · 3.1 KB
/
DZCLabStatusHelper.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#import "DZCLabStatusHelper.h"
#import "DZCLab.h"
@implementation DZCLabStatusHelper
/**
* Make a best guess at whether a lab is currently open.
*
* This is ugly, because the CAEN status API doesn't report a status
* for every lab or building. Additionally, some labs appear twice in the
* status list.
*
* And this will fail on breaks & holidays unless we specifically
* check for these cases.
*/
+ (NSNumber *)statusGuessForLab:(DZCLab *)lab
{
DZCLabStatus status = DZCLabStatusOpen;
NSDate *now = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents =[gregorian components:(NSHourCalendarUnit | NSWeekdayCalendarUnit) fromDate:now];
NSInteger weekday = [dateComponents weekday];
NSInteger hour = [dateComponents hour];
if ([lab.building isEqualToString:@"DC"]) {
// DC hours: http://www.dc.umich.edu/hoursmaps/hours.htm
// 24 hours except for breaks & holidays
status = DZCLabStatusOpen;
}
else if ([lab.building isEqualToString:@"SHAPIRO"]) {
// Ugli hours: http://www.lib.umich.edu/unithours/36.unit/month/January/30/2012/mid_141
// open 8am-5am weekdays; 10am-5am weekends
// closed & special hours on breaks & holidays
if (weekday == 1 || weekday == 7) {
if (hour > 4 && hour < 10) {
status = DZCLabStatusClosed;
}
} else {
if (hour > 4 && hour < 8) {
status = DZCLabStatusClosed;
}
}
}
else if ([lab.building isEqualToString:@"PIERPONT"]) {
// Pierpont hours: http://uunions.umich.edu/pierpont/hours
// open 7am-1am Mon-Thurs
// 7am-12am Fri
// 8am-12am Sat/Sun
// closed & special hours on breaks & holidays
if (weekday == 1 || weekday == 7) {
if (hour < 8) {
status = DZCLabStatusClosed;
}
} else {
if (hour > 0 && hour < 7) {
status = DZCLabStatusClosed;
}
if (weekday == 2 && hour < 7) {
status = DZCLabStatusClosed;
}
}
}
else if ([lab.building isEqualToString:@"AH"]) {
// couldn't find a course for AH hours
// I think AH is 24-hour, possibly except breaks and holidays
status = DZCLabStatusOpen;
}
else if ([lab.building isEqualToString:@"SEB"]) {
// M-F 7am - 9pm ; closed weekends
// http://www.soe.umich.edu/faqs/tag/building/
// closed holidays
if (weekday == 1 || weekday == 7) {
status = DZCLabStatusClosed;
} else {
if (hour < 7 || hour > 20) {
status = DZCLabStatusClosed;
}
}
}
else if ([lab.building isEqualToString:@"BAITS_COMAN"]
|| [lab.building isEqualToString:@"BURSLEY"]
|| [lab.building isEqualToString:@"MO-JO"]) {
// these dorm labs are open 24/7 if you have access to the building
status = DZCLabStatusOpen;
}
return @(status);
}
@end