39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
addMonths,
|
|
currentMonthParis,
|
|
daysInMonth,
|
|
formatDateFr,
|
|
fromIsoDate,
|
|
monthLabelFr,
|
|
monthOf,
|
|
toIsoDate,
|
|
todayParis,
|
|
} from "@/lib/dates";
|
|
|
|
describe("dates", () => {
|
|
it("todayParis follows the Paris calendar day, not UTC", () => {
|
|
expect(todayParis(new Date("2026-10-31T23:30:00Z"))).toBe("2026-11-01");
|
|
expect(todayParis(new Date("2026-10-31T22:30:00Z"))).toBe("2026-10-31");
|
|
expect(currentMonthParis(new Date("2026-10-31T23:30:00Z"))).toBe("2026-11");
|
|
});
|
|
|
|
it("does month arithmetic on strings", () => {
|
|
expect(monthOf("2026-10-31")).toBe("2026-10");
|
|
expect(addMonths("2026-11", 3)).toBe("2027-02");
|
|
expect(addMonths("2026-01", -1)).toBe("2025-12");
|
|
expect(daysInMonth("2028-02")).toBe(29);
|
|
expect(daysInMonth("2027-02")).toBe(28);
|
|
});
|
|
|
|
it("converts Prisma @db.Date values without timezone drift", () => {
|
|
expect(toIsoDate(new Date("2026-10-31T00:00:00Z"))).toBe("2026-10-31");
|
|
expect(fromIsoDate("2026-10-31").toISOString()).toBe("2026-10-31T00:00:00.000Z");
|
|
});
|
|
|
|
it("formats for French display", () => {
|
|
expect(formatDateFr("2026-10-05")).toBe("05/10/2026");
|
|
expect(monthLabelFr("2026-10")).toBe("Octobre 2026");
|
|
});
|
|
});
|