Skip to content
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@base-ui/react": "^1.8.0",
"@better-auth/mongo-adapter": "^1.7.12",
"@date-fns/tz": "^1.5.0",
"@hookform/resolvers": "^7.0.1",
"@tanstack/react-table": "^9.3.1",
"@vercel/analytics": "^2.0.1",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/app/(admin)/admin/registrations/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Metadata } from "next"
import { differenceInYears, format } from "date-fns"
import { differenceInYears } from "date-fns"
import Link from "next/link"
import { notFound } from "next/navigation"
import { ArrowLeftIcon, ExternalLinkIcon } from "lucide-react"
Expand All @@ -14,6 +14,7 @@ import { McBadge } from "@/components/ui/mc-badge"
import { adminRoutes } from "@/config/admin"
import { ABOUT_QUESTIONS } from "@/const/registrations"
import { requireStaff } from "@/lib/auth/session"
import { formatCalendarDate, formatClubTime } from "@/lib/dates"
import { listQuery, parseListParams } from "@/lib/registrations/list-params"
import {
RECOMMENDATIONS_ORIGIN,
Expand Down Expand Up @@ -112,7 +113,7 @@ export default async function RegistrationPage({
<p className="paragraph-md text-muted-foreground">
Submitted on{" "}
<time dateTime={submittedAt.toISOString()}>
{format(submittedAt, "d MMMM yyyy 'at' HH:mm")}
{formatClubTime(submittedAt, "d MMMM yyyy 'at' HH:mm")}
</time>
</p>
</header>
Expand Down Expand Up @@ -186,7 +187,8 @@ export default async function RegistrationPage({
{registration.discord}
</Field>
<Field label="Date of birth">
{format(birthDate, "d MMMM yyyy")} ({differenceInYears(new Date(), birthDate)} years)
{formatCalendarDate(birthDate, "d MMMM yyyy")} (
{differenceInYears(new Date(), birthDate)} years)
</Field>
<Field label="Field of study">{registration.fieldOfStudy}</Field>
<Field label="Year of study">{registration.yearOfStudy}</Field>
Expand Down
4 changes: 2 additions & 2 deletions src/components/admin/registrations/recommendations-table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from "date-fns"
import { formatClubTime } from "@/lib/dates"
import Link from "next/link"

import { Reviewers } from "@/components/admin/registrations/reviewers"
Expand Down Expand Up @@ -92,7 +92,7 @@ export function RecommendationsTable({
</McTableCell>
<McTableCell className="whitespace-nowrap">
<time dateTime={row.submittedAt}>
{format(new Date(row.submittedAt), "d MMM yyyy")}
{formatClubTime(new Date(row.submittedAt), "d MMM yyyy")}
</time>
</McTableCell>
</McTableRow>
Expand Down
5 changes: 3 additions & 2 deletions src/components/admin/registrations/registration-timeline.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format, formatDistanceToNow } from "date-fns"
import { formatDistanceToNow } from "date-fns"
import {
CalendarClockIcon,
CheckIcon,
Expand All @@ -10,6 +10,7 @@ import {
} from "lucide-react"

import { McBadge } from "@/components/ui/mc-badge"
import { formatClubTime } from "@/lib/dates"
import { recommendationTargetName } from "@/lib/registrations/recommendations"
import type { ReviewState } from "@/lib/registrations/status"
import { currentRecommendation, type TimelineEntry } from "@/lib/registrations/timeline"
Expand Down Expand Up @@ -99,7 +100,7 @@ export function RegistrationTimeline({ timeline }: { timeline: TimelineEntry[] }
{badge && <McBadge variant={tone}>{badge}</McBadge>}
<time
dateTime={entry.at.toISOString()}
title={format(entry.at, "d MMMM yyyy 'at' HH:mm")}
title={formatClubTime(entry.at, "d MMMM yyyy 'at' HH:mm")}
className="paragraph-sm text-muted-foreground sm:ml-auto"
>
{formatDistanceToNow(entry.at, { addSuffix: true })}
Expand Down
4 changes: 2 additions & 2 deletions src/components/admin/registrations/registrations-table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from "date-fns"
import { formatClubTime } from "@/lib/dates"
import Link from "next/link"

import { RecommendedBy } from "@/components/admin/registrations/recommended-by"
Expand Down Expand Up @@ -98,7 +98,7 @@ export function RegistrationsTable({
</McTableCell>
<McTableCell className="whitespace-nowrap">
<time dateTime={row.submittedAt}>
{format(new Date(row.submittedAt), "d MMM yyyy")}
{formatClubTime(new Date(row.submittedAt), "d MMM yyyy")}
</time>
</McTableCell>
</McTableRow>
Expand Down
4 changes: 2 additions & 2 deletions src/components/admin/users-table.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client"

import { format } from "date-fns"
import { formatClubTime } from "@/lib/dates"
import { UsersRoundIcon } from "lucide-react"

import { CreateUserDialog } from "@/components/admin/create-user-dialog"
Expand Down Expand Up @@ -46,7 +46,7 @@ const columns = [
column.accessor("createdAt", {
header: "Created",
sortFn: "datetime",
cell: ({ getValue }) => format(new Date(getValue()), "d MMM yyyy"),
cell: ({ getValue }) => formatClubTime(new Date(getValue()), "d MMM yyyy"),
}),
column.display({
id: "actions",
Expand Down
21 changes: 21 additions & 0 deletions src/lib/dates.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest"

import { formatCalendarDate, formatClubTime } from "./dates"

describe("formatClubTime", () => {
it("shows a UTC moment in Algiers time", () => {
expect(formatClubTime(new Date("2026-11-05T21:56:00Z"), "d MMM yyyy HH:mm")).toBe(
"5 Nov 2026 22:56",
)
})

it("moves a late evening UTC moment to the next day", () => {
expect(formatClubTime("2026-11-05T23:30:00.000Z", "d MMM yyyy")).toBe("6 Nov 2026")
})
})

describe("formatCalendarDate", () => {
it("keeps a birth date stored as midnight UTC on its day", () => {
expect(formatCalendarDate(new Date(Date.UTC(2004, 2, 1)), "d MMMM yyyy")).toBe("1 March 2004")
})
})
18 changes: 18 additions & 0 deletions src/lib/dates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { tz } from "@date-fns/tz"
import { format } from "date-fns"

/** The club's timezone: moments (submissions, reviews) are shown in it, whatever the server's or browser's timezone. */
export const CLUB_TIME_ZONE = "Africa/Algiers"

const clubTime = tz(CLUB_TIME_ZONE)
const utc = tz("UTC")

/** Formats a moment stored in UTC (a submission, a review) in the club's local time. */
export function formatClubTime(date: Date | string, pattern: string) {
return format(date, pattern, { in: clubTime })
}

/** Formats a calendar date stored as midnight UTC (a birth date), so it never shifts by a day. */
export function formatCalendarDate(date: Date | string, pattern: string) {
return format(date, pattern, { in: utc })
}
Loading