Connect, collaborate, and grow with a community of TypeScript developers
bug-fix: isValidAdventDay incorrect logic (#1626)
Amanuel Odicho355cf594646b
diff --git a/apps/aot/src/app/leaderboard/layout.tsx b/apps/aot/src/app/leaderboard/layout.tsxindex 978d14d0..cec0ad5b 100644--- a/apps/aot/src/app/leaderboard/layout.tsx+++ b/apps/aot/src/app/leaderboard/layout.tsx@@ -1,4 +1,4 @@-import { getCurrentAdventDay, isValidAdventDay } from '~/utils/time-utils';+import { hasAdventStarted } from '~/utils/time-utils';import { notFound } from 'next/navigation';import { getAllFlags } from '~/utils/feature-flag';import { ComingSoon } from '../coming-soon';@@ -10,8 +10,7 @@ export default async function LeaderboardLayout({ children }: { children: React.return <ComingSoon />;}- const currentAdventDay = getCurrentAdventDay();- if (!isValidAdventDay(currentAdventDay)) return notFound();+ if (!hasAdventStarted()) return notFound();return <>{children}</>;}diff --git a/apps/aot/src/utils/time-utils.ts b/apps/aot/src/utils/time-utils.tsindex 60213991..f8716b49 100644--- a/apps/aot/src/utils/time-utils.ts+++ b/apps/aot/src/utils/time-utils.ts@@ -1,3 +1,8 @@+export function hasAdventStarted() {+ const aoStartTime = new Date(Date.UTC(2024, 11, 1, 5, 0, 0));+ return Date.now() >= aoStartTime.getTime();+}+export function getCurrentAdventDay() {const MS_PER_DAY = 24 * 60 * 60 * 1000;@@ -14,7 +19,7 @@ export function getCurrentAdventDay() {}export function isValidAdventDay(selectedDay: number) {- if (selectedDay < 1 && selectedDay > 25) return false;+ if (selectedDay < 1 || selectedDay > 25) return false;const currentAdventDay = getCurrentAdventDay();return selectedDay <= currentAdventDay;