Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Fix release date logic (#1207)

Amanuel Odicho6c665bd2f95c
diff --git a/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx b/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx
index a1463485..43ce9681 100644
--- a/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx
+++ b/apps/web/src/app/[locale]/aot-2023/_components/card-grid.tsx
@@ -1,6 +1,7 @@
import { prisma } from '@repo/db';
import { TiltableCard } from './tiltable-card';
import { auth, type Session } from '@repo/auth/server';
+import { daysAfterDecemberFirst } from '../../challenge/[slug]/page';
export async function CardGrid() {
const session = await auth();
@@ -58,12 +59,8 @@ async function getTrackChallenges(session: Session | null) {
});
}
-const MS_PER_DAY = 24 * 60 * 60 * 1000;
function revealItems(items: Challenges) {
- const startDate: Date = new Date('2023-12-01');
- const today: Date = new Date();
-
- const daysPassed = Math.floor((today.getTime() - startDate.getTime()) / MS_PER_DAY);
+ const daysPassed = daysAfterDecemberFirst();
return items.map((item, index) => {
const isPastOrCurrentDay = index <= daysPassed;
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/page.tsx b/apps/web/src/app/[locale]/challenge/[slug]/page.tsx
index 60373714..e4d93c24 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/page.tsx
+++ b/apps/web/src/app/[locale]/challenge/[slug]/page.tsx
@@ -44,7 +44,7 @@ export default async function Challenges({ params: { slug } }: Props) {
const [, day = '1'] = slug.split('-');
const daysPassed = daysAfterDecemberFirst();
- if (parseInt(day) > daysPassed) {
+ if (parseInt(day) > daysPassed + 1) {
return notFound();
}
}
@@ -63,12 +63,12 @@ export function isAuthor(session: Session | null, userId?: string | null) {
return userId && session?.user?.id && userId === session?.user?.id;
}
-const MS_PER_DAY = 24 * 60 * 60 * 1000;
-function daysAfterDecemberFirst() {
- const startDate: Date = new Date('2023-12-01');
- const today: Date = new Date();
+export function daysAfterDecemberFirst() {
+ const MS_PER_DAY = 24 * 60 * 60 * 1000;
+ const startDate = new Date('2023-12-01T05:00:00.000Z').getTime();
+ const today = Date.now();
- const daysPassed = Math.floor((today.getTime() - startDate.getTime()) / MS_PER_DAY) + 1;
+ const daysPassed = Math.floor((today - startDate) / MS_PER_DAY);
return daysPassed;
}