-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.js
250 lines (207 loc) · 6.94 KB
/
calendar.js
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
var dd = new Date();
var calendarDate;
var calendarSummary;
var calendarEvent;
var calendarElement = "calendar-event-1";
var calendarDisplay = "checking calendar...";
displayEvent();
var calendarDay = 1;
var calendarEvent1;
var calendarEvent2;
var calendarEvent3;
var calendarTime1;
var calendarTime2;
var calendarTime3;
var calendarIcon1 = document.querySelector("calendar-icon-1");
var calendarIcon2 = document.querySelector("calendar-icon-2");
var calendarIcon3 = document.querySelector("calendar-icon-3");
var calendarToday;
var calendarIconDate1 = "00";
var calendarIconDate2 = "00";
var calendarIconDate3 = "00";
var calendarStartTime;
var calendarEndTime;
var calendarToday = "";
dd.getFullYear() + "-" + (dd.getMonth() + 1) + "-" + dd.getDate();
var calendarTomorrow = "";
dd.getFullYear() + "-" + (dd.getMonth() + 1) + "-" + (dd.getDate() + 1);
displayEvent();
getCalendar();
refresh();
function getCalendar() {
calendarApi; //removed api key for security reasons
fetch(calendarApi)
.then(function (response) {
var data = response.json();
return data;
})
.then(function (data) {
calendarTomorrow =
dd.getFullYear() + "-" + (dd.getMonth() + 1) + "-" + (dd.getDate() + 1);
calendarToday =
dd.getFullYear() + "-" + (dd.getMonth() + 1) + "-" + dd.getDate();
if (data.items[calendarDay] != undefined) {
//get date and summary based off API
calendarSummary = data.items[calendarDay].summary;
calendarDate = data.items[calendarDay].start.dateTime;
//Time
calendarStartTimeHours = data.items[calendarDay].start.dateTime;
calendarStartTimeMinutes = calendarStartTimeHours;
calendarEndTimeHours = data.items[calendarDay].end.dateTime;
calendarEndTimeMinutes = calendarEndTimeHours;
if (calendarDate == undefined) {
calendarDate = data.items[calendarDay].start.date;
calendarEvent = calendarSummary;
} else {
//shorten the date
calendarDate = calendarDate.substring(0, calendarDate.length - 15);
//shorten the time
// EndTime
calendarEndTimeHours = calendarEndTimeHours.substring(11);
calendarEndTimeHours = calendarEndTimeHours.substring(
0,
calendarEndTimeHours.length - 12
);
calendarEndTimeMinutes = calendarEndTimeMinutes.substring(14);
calendarEndTimeMinutes = calendarEndTimeMinutes.substring(
0,
calendarEndTimeMinutes.length - 9
);
//Start Time
calendarStartTimeHours = calendarStartTimeHours.substring(11);
calendarStartTimeHours = calendarStartTimeHours.substring(
0,
calendarStartTimeHours.length - 12
);
calendarStartTimeMinutes = calendarStartTimeMinutes.substring(14);
calendarStartTimeMinutes = calendarStartTimeMinutes.substring(
0,
calendarStartTimeMinutes.length - 9
);
//change to standard time
calendarStartTime =
calendarStartTimeHours > 12
? calendarStartTimeHours -
12 +
":" +
calendarStartTimeMinutes +
" pm"
: calendarStartTimeHours + ":" + calendarStartTimeMinutes + " am";
calendarEndTime =
calendarEndTimeHours > 12
? calendarEndTimeHours - 12 + ":" + calendarEndTimeMinutes + " pm"
: calendarEndTimeHours + ":" + calendarEndTimeMinutes + " am";
calendarIconDate = calendarDate;
calendarIconDate = calendarIconDate.substring(8);
//simplify
//change work name
if (calendarSummary == "Hotschedules: FOH General Front of House") {
calendarSummary = "Chick-fil-A";
}
// final
calendarEvent = calendarSummary;
}
checkDate();
} else {
finalDisplay();
}
})
.catch(function (err) {
console.log("calendar: " + err);
});
}
// checkdate
function checkDate() {
//checks to see if the events date matches todays date
if (calendarDate == calendarToday) {
priority = 1;
adVerb = "Today";
subCheckDate();
} else if (calendarDate == calendarTomorrow) {
priority = 2;
adVerb = "Tomorrow";
subCheckDate();
//adding to the day variable to check the next event in the list
} else {
calendarDay = calendarDay + 1;
getCalendar();
}
}
function subCheckDate() {
console.log(calendarEvent + " Event # " + calendarDay);
if (calendarEvent1 == "") {
priority1 = priority;
calendarEvent1 = calendarEvent;
calendarTime1 = adVerb + " at " + calendarStartTime;
calendarIconDate1 = calendarIconDate + "c";
console.log(calendarEvent + "=1");
calendarDay = calendarDay + 1;
getCalendar();
// first slot was full, so now checking if the second slot is empty
} else if (calendarEvent2 == "") {
priority2 = priority;
calendarEvent2 = calendarEvent;
calendarTime2 = adVerb + " at " + calendarStartTime;
calendarIconDate2 = calendarIconDate + "c";
console.log(calendarEvent + "=2");
calendarDay = calendarDay + 1;
getCalendar();
// the second slot was full as well, checking if the third slot is empty
} else if (calendarEvent3 == "") {
priority3 = priority;
calendarEvent3 = calendarEvent;
calendarTime3 = adVerb + " at " + calendarStartTime;
calendarIconDate3 = calendarIconDate + "c";
console.log(calendarEvent + "=3");
finalDisplay();
}
}
function refresh() {
calendarDate = "";
calendarSummary = "";
calendarEvent = "";
dd = new Date();
calendarEvent1 = "";
calendarEvent2 = "";
calendarEvent3 = "";
calendarIconDate1 = "00";
calendarIconDate2 = "00";
calendarIconDate3 = "00";
calendarTime1 = "";
calendarTime2 = "";
calendarTime3 = "";
calendarStartTime = "";
calendarEndTime = "";
calendarDay = 70;
getCalendar();
setTimeout(refresh, 60000);
}
function displayEvent() {
document.getElementById(calendarElement).textContent = calendarDisplay;
}
function finalDisplay() {
calendarElement = "calendar-event-1";
calendarDisplay = calendarEvent1;
displayEvent();
calendarElement = "calendar-event-2";
calendarDisplay = calendarEvent2;
displayEvent();
calendarElement = "calendar-event-3";
calendarDisplay = calendarEvent3;
displayEvent();
calendarElement = "calendar-time-1";
calendarDisplay = calendarTime1;
displayEvent();
calendarElement = "calendar-time-2";
calendarDisplay = calendarTime2;
displayEvent();
calendarElement = "calendar-time-3";
calendarDisplay = calendarTime3;
displayEvent();
document.getElementById("calendar-icon-1").src =
"icons/calendar/" + calendarIconDate1 + ".png";
document.getElementById("calendar-icon-2").src =
"icons/calendar/" + calendarIconDate2 + ".png";
document.getElementById("calendar-icon-3").src =
"icons/calendar/" + calendarIconDate3 + ".png";
}