account for leap years

This commit is contained in:
Oliver Bryan
2025-09-30 20:46:37 +01:00
parent 342bca31e4
commit d28cda7f96

View File

@@ -13,7 +13,7 @@ const uniqueId = `time-since-${Math.random().toString(36).substring(2, 9)}`;
function updateTimeAlive() { function updateTimeAlive() {
let years = roundToDp( let years = roundToDp(
(currentTimeMS - dateMS + msElapsed) / (60 * 60 * 24 * 365 * 1000), (currentTimeMS - dateMS + msElapsed) / (60 * 60 * 24 * 365.25 * 1000),
2 2
); );
let milliseconds = currentTimeMS - dateMS + msElapsed; let milliseconds = currentTimeMS - dateMS + msElapsed;
@@ -26,7 +26,7 @@ const uniqueId = `time-since-${Math.random().toString(36).substring(2, 9)}`;
function roundToDp(num, dp) { function roundToDp(num, dp) {
const factor = Math.pow(10, dp); const factor = Math.pow(10, dp);
return Math.round(num * factor) / factor; return Math.floor(num * factor) / factor;
} }
updateTimeAlive(); updateTimeAlive();