From a1d266f0d3b620bd119ee28f177ca1fea0874df5 Mon Sep 17 00:00:00 2001 From: Naju Mancheril Date: Thu, 15 Jun 2023 11:01:08 -0400 Subject: [PATCH] Invoke getTime() on the Date value and not on the date signal (#1284) --- docs/getting-started/adding-interactivity.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/getting-started/adding-interactivity.md b/docs/getting-started/adding-interactivity.md index 767ec13e..b840c0ca 100644 --- a/docs/getting-started/adding-interactivity.md +++ b/docs/getting-started/adding-interactivity.md @@ -54,14 +54,17 @@ export default function Countdown(props: { target: string }) { return () => clearInterval(timer); }, [props.target]); + const secondsLeft = Math.floor( + (target.getTime() - now.value.getTime()) / 1000, + ); + // If the target date has passed, we stop counting down. - if (now > target) { + if (secondsLeft <= 0) { return 🎉; } // Otherwise, we format the remaining time using `Intl.RelativeTimeFormat` and // render it. - const secondsLeft = Math.floor((target.getTime() - now.getTime()) / 1000); return {timeFmt.format(secondsLeft, "seconds")}; } ```