-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (28 loc) · 990 Bytes
/
app.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
(() => {
const hackathonDate = new Date("December 3, 2020 00:00:00");
const countdown = document.querySelector(".landing__countdown");
let dateString = "";
const updateTime = () => {
const formatInt = (i) =>
i.toLocaleString("pl-PL", { minimumIntegerDigits: 2 });
let diffInSeconds = Math.abs(hackathonDate - Date.now()) / 1000;
if(diffInSeconds > 0){
let secondsLeft = parseInt(diffInSeconds % 60);
let minutesLeft = parseInt((diffInSeconds / 60) % 60);
let hoursLeft = parseInt((diffInSeconds / (60 * 60)) % 24);
let daysLeft = parseInt(diffInSeconds / (60 * 60 * 24));
dateString = `${formatInt(daysLeft)}:${formatInt(
hoursLeft
)}:${formatInt(minutesLeft)}:${formatInt(secondsLeft)}`;
}
else{
dateString = "OTWARTE";
}
countdown.setAttribute("time-left", dateString);
countdown.textContent = dateString;
};
setInterval(() => {
updateTime();
}, 1000);
updateTime();
})();