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
34 changes: 25 additions & 9 deletions test/FormatDate.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import assert from "node:assert/strict";
import { describe, it } from "node:test";
import { formatJoinDate } from "../src/lib/format-date";

const validIsoDate = "2026-07-27T12:00:00.000Z";
const expectedDate = new Date(validIsoDate).toLocaleDateString(undefined, {
year: "numeric",
month: "long",
day: "numeric",
});
const expectedDate = (value: string) =>
new Date(value).toLocaleDateString(undefined, {
year: "numeric",
month: "long",
day: "numeric",
});

describe("formatJoinDate", () => {
it("formats a valid ISO date", () => {
const value = "2026-07-27T12:00:00.000Z";
assert.equal(formatJoinDate(value), expectedDate(value));
});

assert.equal(formatJoinDate(validIsoDate), expectedDate);
assert.equal(formatJoinDate("not-a-date"), "not-a-date");
it("returns an invalid date unchanged", () => {
assert.equal(formatJoinDate("not-a-date"), "not-a-date");
});

console.log("FormatDate tests passed.");
it("returns an empty string unchanged", () => {
assert.equal(formatJoinDate(""), "");
});

it("formats an ISO date with a timezone offset", () => {
const value = "2026-07-27T18:30:00+05:30";
assert.equal(formatJoinDate(value), expectedDate(value));
});
});