Skip to content
Merged
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
29 changes: 29 additions & 0 deletions __tests__/lib/format-date.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, it, expect } from "vitest";
import { formatDate } from "@/lib/format-date";

describe("formatDate", () => {
it("formats a standard date: Jan 15, 2024, 3:45 PM", () => {
const date = new Date(2024, 0, 15, 15, 45);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use UTC date construction for deterministic test behavior.

Line 6 should use Date.UTC(...) (as requested in the issue objective) to avoid environment-dependent drift in date creation semantics.

Suggested fix
-    const date = new Date(2024, 0, 15, 15, 45);
+    const date = new Date(Date.UTC(2024, 0, 15, 15, 45));
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const date = new Date(2024, 0, 15, 15, 45);
const date = new Date(Date.UTC(2024, 0, 15, 15, 45));
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@__tests__/lib/format-date.test.ts` at line 6, The test creates a local-time
Date with new Date(2024, 0, 15, 15, 45) which can be non-deterministic across
environments; change the construction to use UTC by replacing that line with new
Date(Date.UTC(2024, 0, 15, 15, 45)) (locate the const date in
__tests__/lib/format-date.test.ts) so the test uses a deterministic UTC
timestamp.

expect(formatDate(date)).toBe("Jan 15, 2024, 3:45 PM");
});

it("formats start of month: Mar 1, 2024, 9:30 AM", () => {
const date = new Date(2024, 2, 1, 9, 30);
expect(formatDate(date)).toBe("Mar 1, 2024, 9:30 AM");
});

it("formats midnight: Feb 10, 2024, 12:00 AM", () => {
const date = new Date(2024, 1, 10, 0, 0);
expect(formatDate(date)).toBe("Feb 10, 2024, 12:00 AM");
});

it("formats single-digit day: Jul 5, 2024, 2:15 PM", () => {
const date = new Date(2024, 6, 5, 14, 15);
expect(formatDate(date)).toBe("Jul 5, 2024, 2:15 PM");
});

it("formats end of year: Dec 31, 2024, 11:59 PM", () => {
const date = new Date(2024, 11, 31, 23, 59);
expect(formatDate(date)).toBe("Dec 31, 2024, 11:59 PM");
});
});