From c48b82148a80d35d6bb5aa1b2d00acaf9db47770 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Wed, 13 Dec 2023 00:44:35 +0100 Subject: [PATCH] Fix morning time --- src/pages/parts/home/HeroPart.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pages/parts/home/HeroPart.tsx b/src/pages/parts/home/HeroPart.tsx index 17a1172c..6b2ef282 100644 --- a/src/pages/parts/home/HeroPart.tsx +++ b/src/pages/parts/home/HeroPart.tsx @@ -16,6 +16,14 @@ export interface HeroPartProps { searchParams: ReturnType; } +function getTimeOfDay(date: Date): "night" | "morning" | "day" { + const hour = date.getHours(); + if (hour < 5) return "night"; + if (hour < 12) return "morning"; + if (hour < 19) return "day"; + return "night"; +} + export function HeroPart({ setIsSticky, searchParams }: HeroPartProps) { const { t: randomT } = useRandomTranslation(); const { t } = useTranslation(); @@ -44,11 +52,7 @@ export function HeroPart({ setIsSticky, searchParams }: HeroPartProps) { } }, [windowWidth]); - let time = "night"; - const hour = new Date().getHours(); - if (hour < 12) time = "morning"; - else if (hour < 19) time = "day"; - + const time = getTimeOfDay(new Date()); const title = randomT(`home.titles.${time}`); const inputRef = useRef(null);