Skip to content

Commit 9830386

Browse files
committed
Switch both clock options to luxon.
1 parent 113eb80 commit 9830386

File tree

1 file changed

+8
-38
lines changed

1 file changed

+8
-38
lines changed

slides/templates/regular/index.html.j2

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,6 @@ require(
278278
}
279279
);
280280
281-
const getCurrentTime = () => {
282-
const now = new Date();
283-
let hours = now.getHours();
284-
let minutes = now.getMinutes();
285-
const ampm = hours >= 12 ? 'PM' : 'AM';
286-
hours = hours % 12;
287-
hours = hours ? hours : 12; // the hour '0' should be '12'
288-
minutes = minutes < 10 ? '0' + minutes : minutes;
289-
return { now, time: `${hours}:${minutes} ${ampm}`};
290-
}
291-
292281
// add clock
293282
let updateClockInterval;
294283
Reveal.addKeyBinding(
@@ -300,7 +289,7 @@ require(
300289
updateClockInterval = 'cleared';
301290
}
302291
else {
303-
const updateTime = () => $('.clock').text(getCurrentTime().time);
292+
const updateTime = () => $('.clock').text(DateTime.now().toFormat('hh:mm a'));
304293
updateTime();
305294
updateClockInterval = setInterval(updateTime, 1000);
306295
}
@@ -322,41 +311,22 @@ require(
322311
323312
if (!isNaN(updateFMWInterval)) cleanup();
324313
325-
const endAt = new Date();
326-
const warnAt = new Date();
327-
328314
const [time, ampm] = input.split(' ');
329315
let [endHour, endMinute] = time.split(':').map((x) => parseInt(x));
330316
const militaryTime = ampm === undefined;
331317
let shiftHours = militaryTime ? 0 : (ampm.toLowerCase() === 'pm' ? 12 : 0);
332318
333-
endAt.setHours(endHour + shiftHours);
334-
endAt.setMinutes(endMinute);
335-
endAt.setSeconds(0);
336-
337-
endMinute -= 5;
338-
if (endMinute < 0) {
339-
endMinute += 60;
340-
endHour -= 1;
341-
}
342-
if (endHour === 0 && !militaryTime) {
343-
endHour = 12;
344-
shiftHours = 0;
345-
}
346-
else if (endHour < 0 && militaryTime) {
347-
endHour += 24;
348-
warnAt.setDate(warnAt.getDate() - 1);
349-
}
350-
351-
warnAt.setHours(endHour + shiftHours);
352-
warnAt.setMinutes(endMinute);
353-
warnAt.setSeconds(0);
319+
const endAt = DateTime.now().startOf('minute').set({
320+
hour: endHour + shiftHours,
321+
minute: endMinute
322+
});
323+
const warnAt = endAt.minus({ minutes: 5 });
354324
355325
const checkTime = () => {
356-
const { now, time } = getCurrentTime();
326+
const now = DateTime.now();
357327
if (now >= endAt) cleanup();
358328
else if (now >= warnAt) {
359-
$('.clock').text(time).css('color', 'red');
329+
$('.clock').text(now.toFormat('hh:mm a')).css('color', 'red');
360330
}
361331
}
362332
updateFMWInterval = setInterval(checkTime, 1000);

0 commit comments

Comments
 (0)