From d28cda7f96bff6c48c2ca5b14d3e8857a7202971 Mon Sep 17 00:00:00 2001 From: Oliver Bryan <04oliverbryan@gmail.com> Date: Tue, 30 Sep 2025 20:46:37 +0100 Subject: [PATCH] account for leap years --- src/components/TimeSince.astro | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/TimeSince.astro b/src/components/TimeSince.astro index d55d9e60..c66e8127 100644 --- a/src/components/TimeSince.astro +++ b/src/components/TimeSince.astro @@ -13,7 +13,7 @@ const uniqueId = `time-since-${Math.random().toString(36).substring(2, 9)}`; function updateTimeAlive() { let years = roundToDp( - (currentTimeMS - dateMS + msElapsed) / (60 * 60 * 24 * 365 * 1000), + (currentTimeMS - dateMS + msElapsed) / (60 * 60 * 24 * 365.25 * 1000), 2 ); let milliseconds = currentTimeMS - dateMS + msElapsed; @@ -26,7 +26,7 @@ const uniqueId = `time-since-${Math.random().toString(36).substring(2, 9)}`; function roundToDp(num, dp) { const factor = Math.pow(10, dp); - return Math.round(num * factor) / factor; + return Math.floor(num * factor) / factor; } updateTimeAlive();