Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions apps/web/src/app/register/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Card } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import { Skeleton } from "@/components/ui/skeleton";
import { TextScramble } from "@/components/ui/text-scramble";
import { calculateTimeLeft } from "@/libs/date";
import { fetchQuery } from "@/libs/server/client";
import { Mail } from "lucide-react";
import Image from "next/image";
Expand Down Expand Up @@ -73,10 +74,17 @@ function RegisterPage() {
<div className="flex items-baseline justify-between">
<p className="text-[1rem] sm:text-[1.25rem]">ข้อมูลส่วนบุคคล</p>
<TextScramble trigger className="text-[1rem] sm:text-[1.25rem]">
{`เหลือเวลาอีก ${Math.ceil(
(new Date("2025-03-13").getTime() - new Date().getTime()) /
(1000 * 60 * 60 * 24),
)} วัน`}
{(() => {
const { isLate, daysLeft, hoursLeft } = calculateTimeLeft(
new Date("2025-03-13T23:59:59+07:00"),
);

if (isLate) return "หมดเขตรับสมัครแล้ว";

return daysLeft > 0
? `เหลือเวลาอีก ${daysLeft} วัน`
: `เหลือเวลาอีก ${hoursLeft} ชั่วโมง`;
})()}
</TextScramble>
</div>
<Separator />
Expand Down
12 changes: 7 additions & 5 deletions apps/web/src/components/navigate/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer";
import { calculateTimeLeft } from "@/libs/date";
import { ReactNode } from "react";
import { TextShimmerWave } from "../text/text-shimmer-wave";
import { Banner } from "../ui/banner";
Expand Down Expand Up @@ -69,13 +70,14 @@ export default function Navbar({ items, extra }: NavbarProps) {
className="cursor-pointer text-base font-medium transition-colors [--base-color:var(--color-vermilion)] [--base-gradient-color:var(--color-vermilion-1)] dark:[--base-color:var(--color-vermilion)] dark:[--base-gradient-color:var(--color-vermilion-1)]"
>
{(() => {
const daysLeft = Math.floor(
(new Date("2025-03-14T00:00:00+07:00").getTime() -
Date.now()) /
(1000 * 60 * 60 * 24),
const { isLate, daysLeft } = calculateTimeLeft(
new Date("2025-03-13T23:59:59+07:00"),
);

if (isLate) return "หมดเขตรับสมัครแล้ว";

return daysLeft > 0
? `เหลือเวลาอีก ${daysLeft.toString()} วันจะหมดเขตรับสมัครแล้วนะ รีบสมัครเลย!`
? `เหลือเวลาอีก ${daysLeft} วันจะหมดเขตรับสมัครแล้วนะ รีบสมัครเลย!`
: "เหลือเวลาอีกไม่ถึง 1 วันแล้วนะ รีบสมัครเลย! (ปิดรับสมัครเวลา 23:59:59)";
})()}
</TextShimmerWave>
Expand Down
15 changes: 15 additions & 0 deletions apps/web/src/libs/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ export function getAcademicYearFormDate(date: Date) {
return year + 543;
}
}

export function calculateTimeLeft(target: Date) {
const now = new Date();
const diffMs = target.getTime() - now.getTime();
const isLate = diffMs < 0;

const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));
const hours = Math.floor((diffMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));

return {
isLate,
daysLeft: days,
hoursLeft: hours,
};
}
Loading