Merge pull request #15 from netlify/better_counting
Use UTC dates to count the days without incidents.
This commit is contained in:
commit
5bed59b2e0
@ -1,13 +1,16 @@
|
|||||||
// JS Goes here - ES6 supported
|
// JS Goes here - ES6 supported
|
||||||
const daysSince = document.getElementById("days-since-latest");
|
const daysSince = document.getElementById("days-since-latest");
|
||||||
console.log(daysSince);
|
|
||||||
if (daysSince) {
|
if (daysSince) {
|
||||||
const aDay = 1000*60*60*24;
|
const aDay = 1000*60*60*24;
|
||||||
const dateSince = daysSince.getAttribute("data-latest-incident-date");
|
|
||||||
|
|
||||||
const timeSince = new Date() - new Date(dateSince);
|
const dateSince = new Date(daysSince.getAttribute("data-latest-incident-date"));
|
||||||
|
const now = new Date();
|
||||||
|
|
||||||
|
const timeSince = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()) -
|
||||||
|
new Date(dateSince.getUTCFullYear(), dateSince.getUTCMonth(), dateSince.getUTCDate());
|
||||||
const endDays = Math.floor(timeSince / aDay);
|
const endDays = Math.floor(timeSince / aDay);
|
||||||
|
|
||||||
const count = endDays == 1 ? `${endDays} day` : `${endDays} days`;
|
const count = endDays === 1 ? `${endDays} day` : `${endDays} days`;
|
||||||
daysSince.innerHTML = `${count} since last incident`;
|
daysSince.innerHTML = `${count} since last incident`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user