-
Notifications
You must be signed in to change notification settings - Fork 0
/
spc.js
281 lines (237 loc) · 8.53 KB
/
spc.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
const day1span = document.getElementById("spc-1-countdown");
const day2span = document.getElementById("spc-2-countdown");
const day3span = document.getElementById("spc-3-countdown");
const day4to8span = document.getElementById("spc-4-8-countdown");
const day1progress = document.getElementById("spc-1-progress-bar");
const day2progress = document.getElementById("spc-2-progress-bar");
const day3progress = document.getElementById("spc-3-progress-bar");
const day4to8progress = document.getElementById("spc-4-8-progress-bar");
const day1localTime = document.getElementById("spc-1-local-time");
const day2localTime = document.getElementById("spc-2-local-time");
const day3localTime = document.getElementById("spc-3-local-time");
const day4to8localTime = document.getElementById("spc-4-8-local-time");
// Day 1 outlooks are issued at 0600 UTC, 1300 UTC, 1630 UTC, 2000 UTC, and 0100 UTC.
const day1times = ["01:00", "06:00", "13:00", "16:30", "20:00"];
// Day 2 outlooks are issued at 0600 UTC and 1730 UTC
const day2times = ["06:00", "17:30"];
// Day 3 outlooks are issued at 0730 UTC
const day3times = ["07:30"];
// Day 4-8 outlooks are issued at 0900 UTC
const day4to8times = ["09:00"];
function isTomorrow(date) {
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
return (
date.getDate() === tomorrow.getDate() &&
date.getMonth() === tomorrow.getMonth() &&
date.getFullYear() === tomorrow.getFullYear()
);
}
function updateCountdowns() {
const currentTime = new Date();
const currentUTCTime = currentTime.toISOString().slice(11, 16);
let day1time = null;
let day2time = null;
let day3time = null;
let day4to8time = null;
for (const time of day1times) {
if (time > currentUTCTime) {
day1time = time;
break;
}
}
for (const time of day2times) {
if (time > currentUTCTime) {
day2time = time;
break;
}
}
for (const time of day3times) {
if (time > currentUTCTime) {
day3time = time;
break;
}
}
for (const time of day4to8times) {
if (time > currentUTCTime) {
day4to8time = time;
break;
}
}
let day1InFuture = false;
let day2InFuture = false;
let day3InFuture = false;
let day4to8InFuture = false;
// Check if the current time is after the last issuance time for each day
if (day1time === null) {
day1time = day1times[0];
day1InFuture = true;
}
if (day2time === null) {
day2time = day2times[0];
day2InFuture = true;
}
if (day3time === null) {
day3time = day3times[0];
day3InFuture = true;
}
if (day4to8time === null) {
day4to8time = day4to8times[0];
day4to8InFuture = true;
}
const day1date = new Date();
const day2date = new Date();
const day3date = new Date();
const day4to8date = new Date();
day1date.setUTCHours(parseInt(day1time.slice(0, 2), 10));
day1date.setUTCMinutes(parseInt(day1time.slice(3), 10));
day1date.setUTCSeconds(0);
day1date.setUTCMilliseconds(0);
day2date.setUTCHours(parseInt(day2time.slice(0, 2), 10));
day2date.setUTCMinutes(parseInt(day2time.slice(3), 10));
day2date.setUTCSeconds(0);
day2date.setUTCMilliseconds(0);
day3date.setUTCHours(parseInt(day3time.slice(0, 2), 10));
day3date.setUTCMinutes(parseInt(day3time.slice(3), 10));
day3date.setUTCSeconds(0);
day3date.setUTCMilliseconds(0);
day4to8date.setUTCHours(parseInt(day4to8time.slice(0, 2), 10));
day4to8date.setUTCMinutes(parseInt(day4to8time.slice(3), 10));
day4to8date.setUTCSeconds(0);
day4to8date.setUTCMilliseconds(0);
if (day1InFuture) {
day1date.setDate(day1date.getDate() + 1);
}
if (day2InFuture) {
day2date.setDate(day2date.getDate() + 1);
}
if (day3InFuture) {
day3date.setDate(day3date.getDate() + 1);
}
if (day4to8InFuture) {
day4to8date.setDate(day4to8date.getDate() + 1);
}
const day1diff = day1date - currentTime;
const day2diff = day2date - currentTime;
const day3diff = day3date - currentTime;
const day4to8diff = day4to8date - currentTime;
// If minutes or seconds are less than 10, add a leading zero
const day1diffHours = Math.floor(day1diff / 3600000);
const day1diffMinutes = Math.floor((day1diff % 3600000) / 60000)
.toString()
.padStart(2, "0");
const day1diffSeconds = Math.floor((day1diff % 60000) / 1000)
.toString()
.padStart(2, "0");
const day2diffHours = Math.floor(day2diff / 3600000);
const day2diffMinutes = Math.floor((day2diff % 3600000) / 60000)
.toString()
.padStart(2, "0");
const day2diffSeconds = Math.floor((day2diff % 60000) / 1000)
.toString()
.padStart(2, "0");
const day3diffHours = Math.floor(day3diff / 3600000);
const day3diffMinutes = Math.floor((day3diff % 3600000) / 60000)
.toString()
.padStart(2, "0");
const day3diffSeconds = Math.floor((day3diff % 60000) / 1000)
.toString()
.padStart(2, "0");
const day4to8diffHours = Math.floor(day4to8diff / 3600000);
const day4to8diffMinutes = Math.floor((day4to8diff % 3600000) / 60000)
.toString()
.padStart(2, "0");
const day4to8diffSeconds = Math.floor((day4to8diff % 60000) / 1000)
.toString()
.padStart(2, "0");
day1span.textContent = `${day1diffHours}:${day1diffMinutes}:${day1diffSeconds}`;
day2span.textContent = `${day2diffHours}:${day2diffMinutes}:${day2diffSeconds}`;
day3span.textContent = `${day3diffHours}:${day3diffMinutes}:${day3diffSeconds}`;
day4to8span.textContent = `${day4to8diffHours}:${day4to8diffMinutes}:${day4to8diffSeconds}`;
const day1totalSeconds = day1diff / 1000;
const day2totalSeconds = day2diff / 1000;
const day3totalSeconds = day3diff / 1000;
const day4to8totalSeconds = day4to8diff / 1000;
let day1totalSecondsInDay = 0;
let day2totalSecondsInDay = 0;
// Get the seconds between the previous issuance and the next issuance
switch (day1time) {
case "01:00":
day1totalSecondsInDay = 18000;
break;
case "06:00":
day1totalSecondsInDay = 18000;
break;
case "13:00":
day1totalSecondsInDay = 25200;
break;
case "16:30":
day1totalSecondsInDay = 12600;
break;
case "20:00":
day1totalSecondsInDay = 12600;
break;
}
switch (day2time) {
case "06:00":
day2totalSecondsInDay = 39600;
break;
case "17:30":
day2totalSecondsInDay = 61200;
break;
}
const day3totalSecondsInDay = 86400;
const day4to8totalSecondsInDay = 86400;
const day1progressValue =
(day1totalSecondsInDay - day1totalSeconds) / day1totalSecondsInDay;
const day2progressValue =
(day2totalSecondsInDay - day2totalSeconds) / day2totalSecondsInDay;
const day3progressValue =
(day3totalSecondsInDay - day3totalSeconds) / day3totalSecondsInDay;
const day4to8progressValue =
(day4to8totalSecondsInDay - day4to8totalSeconds) / day4to8totalSecondsInDay;
day1progress.style.width = `${day1progressValue * 100}%`;
day2progress.style.width = `${day2progressValue * 100}%`;
day3progress.style.width = `${day3progressValue * 100}%`;
day4to8progress.style.width = `${day4to8progressValue * 100}%`;
// Show the user when the next outlook comes out in their local time
const day1localDate = new Date(day1date);
const day2localDate = new Date(day2date);
const day3localDate = new Date(day3date);
const day4to8localDate = new Date(day4to8date);
// Check if the local time is tomorrow
const day1IsTomorrowLocal = isTomorrow(day1localDate);
const day2IsTomorrowLocal = isTomorrow(day2localDate);
const day3IsTomorrowLocal = isTomorrow(day3localDate);
const day4to8IsTomorrowLocal = isTomorrow(day4to8localDate);
day1localTime.textContent =
(day1IsTomorrowLocal ? "Tomorrow at " : "") +
day1localDate.toLocaleTimeString("en-US", {
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
hour: "2-digit",
minute: "2-digit",
});
day2localTime.textContent =
(day2IsTomorrowLocal ? "Tomorrow at " : "") +
day2localDate.toLocaleTimeString("en-US", {
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
hour: "2-digit",
minute: "2-digit",
});
day3localTime.textContent =
(day3IsTomorrowLocal ? "Tomorrow at " : "") +
day3localDate.toLocaleTimeString("en-US", {
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
hour: "2-digit",
minute: "2-digit",
});
day4to8localTime.textContent =
(day4to8IsTomorrowLocal ? "Tomorrow at " : "") +
day4to8localDate.toLocaleTimeString("en-US", {
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
hour: "2-digit",
minute: "2-digit",
});
setTimeout(updateCountdowns, 1000);
}
updateCountdowns();