From 47e467037b1c0c11fdd136179a1738cdb43e6d58 Mon Sep 17 00:00:00 2001 From: Jimmy Liu Date: Mon, 12 Dec 2022 17:10:58 -0500 Subject: [PATCH 1/4] Initial commit --- .gitignore | 1 + scavenger2022/core/templates/core/base.html | 28 +++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b93db00..16662d4 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ __pycache__ .build scavenger2022/db.sqlite3 *.pyc +scavenger2022/venv/ diff --git a/scavenger2022/core/templates/core/base.html b/scavenger2022/core/templates/core/base.html index c279f1f..9461d20 100644 --- a/scavenger2022/core/templates/core/base.html +++ b/scavenger2022/core/templates/core/base.html @@ -17,26 +17,34 @@ const cutonText = '{% translate "Ends in:" %}' const cutoff = {{ CUTOFF.timestamp }} * 1000 const cuton = {{ CUTON.timestamp }} * 1000 + + console.log("Cutoff:",cutoff); + const intervalId = setInterval(() => { - let cutoff = true - let d = (cutoff - Date.now()) / 1000 + let unfinished = true + let d = Math.floor((cutoff - Date.now()) / 1000) if (d < 0) { d = (cuton - Date.now()) / 1000 - cutoff = false + unfinished = false } - const hour = Math.round(d / 3600 % 24) - 1 - const minute = Math.round(d / 60 % 60) - const second = Math.round(d % 60) - const day = Math.round(d % (3600*24) / (3600*24)) + + console.log("d", d); + + const day = Math.floor(d / 86400) + const hour = Math.floor((d - day * 86400) / 3600) + const minute = Math.floor((d - day * 86400 - hour * 3600) / 60) + const second = d % 60 let s = '' if (day == 1) s += '1 day, ' - else if (day == 0); - else s += `${day} days, ` + else if (day == 0) {} + else { + s += `${day} days, ` + } s += ('0' + hour).slice(-2) + ':' s += ('0' + minute).slice(-2) + ':' s += ('0' + second).slice(-2) e.innerText = s - eText.innerText = cutoff ? cutoffText : cutonText + eText.innerText = unfinished ? cutoffText : cutonText }, 1000) {% endif %} From 58ff7504eaab31bc7bcc0a303ea1363152ecbdd5 Mon Sep 17 00:00:00 2001 From: Jimmy Liu Date: Mon, 12 Dec 2022 18:34:42 -0500 Subject: [PATCH 2/4] Fix time calculation --- scavenger2022/core/templates/core/base.html | 35 +++++++++++++++------ 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/scavenger2022/core/templates/core/base.html b/scavenger2022/core/templates/core/base.html index 9461d20..80c701d 100644 --- a/scavenger2022/core/templates/core/base.html +++ b/scavenger2022/core/templates/core/base.html @@ -18,17 +18,23 @@ const cutoff = {{ CUTOFF.timestamp }} * 1000 const cuton = {{ CUTON.timestamp }} * 1000 - console.log("Cutoff:",cutoff); - const intervalId = setInterval(() => { - let unfinished = true - let d = Math.floor((cutoff - Date.now()) / 1000) + let started = false + let finished = false + let d = Math.floor((cuton - Date.now()) / 1000) + //console.log("Initial d:", d); if (d < 0) { - d = (cuton - Date.now()) / 1000 - unfinished = false + d = Math.floor((cutoff - Date.now()) / 1000); + if (d < 0) { + finished = true + } + started = true } - console.log("d", d); + /*console.log("Cuton:", cuton); + console.log("Cutoff:", cutoff); + console.log("Now:", Date.now()); + console.log("d:", d);*/ const day = Math.floor(d / 86400) const hour = Math.floor((d - day * 86400) / 3600) @@ -44,7 +50,17 @@ s += ('0' + minute).slice(-2) + ':' s += ('0' + second).slice(-2) e.innerText = s - eText.innerText = unfinished ? cutoffText : cutonText + if (started) { + if (finished) { + eText.innerText = "Scavenger hunt finished!" + } + else { + eText.innerText = cutonText; + } + } + else { + eText.innerText = cutoffText; + } }, 1000) {% endif %} @@ -100,7 +116,8 @@ {% else %} From 032696cd38f6a8bd1253950f35cb45efcefb1b8c Mon Sep 17 00:00:00 2001 From: Jimmy Liu Date: Mon, 12 Dec 2022 23:26:26 -0500 Subject: [PATCH 3/4] Calculate time right away Define calculateTime() function for calculating remaining time. Call this function at DOM initialization --- scavenger2022/core/templates/core/base.html | 22 +++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/scavenger2022/core/templates/core/base.html b/scavenger2022/core/templates/core/base.html index 80c701d..13dd467 100644 --- a/scavenger2022/core/templates/core/base.html +++ b/scavenger2022/core/templates/core/base.html @@ -11,14 +11,7 @@ {% if CUTOFF_BEFORE or CUTON_BEFORE %} {% endif %} From e211ad0ecd8c284f35ee56551e416ce906b9605b Mon Sep 17 00:00:00 2001 From: nyiyui <+@nyiyui.ca> Date: Tue, 13 Dec 2022 01:35:25 -0500 Subject: [PATCH 4/4] fix css --- scavenger2022/core/static/core/base.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scavenger2022/core/static/core/base.css b/scavenger2022/core/static/core/base.css index 7461d34..86c0b13 100644 --- a/scavenger2022/core/static/core/base.css +++ b/scavenger2022/core/static/core/base.css @@ -41,7 +41,7 @@ body > nav { padding: 4px; } -#start-header { +#countdown-header { text-align: center; }