mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 03:53:13 +00:00
Restore todayIso() after parent merge reintroduced UTC slice, and keep the wizard-date-utils regression test. Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
||
import {
|
||
fmtDateRange,
|
||
fmtShortDate,
|
||
pad2,
|
||
rangeDayCount,
|
||
todayIso,
|
||
} from "@/domain/work-orders/utils/wizard-date-utils";
|
||
|
||
describe("fmtShortDate", () => {
|
||
it("formats ISO dates as Mon D", () => {
|
||
expect(fmtShortDate("2026-06-08")).toBe("Jun 8");
|
||
});
|
||
|
||
it("returns em dash for invalid input", () => {
|
||
expect(fmtShortDate("")).toBe("—");
|
||
expect(fmtShortDate("nope")).toBe("—");
|
||
});
|
||
});
|
||
|
||
describe("fmtDateRange", () => {
|
||
it("joins start and end with en dash", () => {
|
||
expect(fmtDateRange("2026-06-08", "2026-06-12")).toBe("Jun 8 – Jun 12");
|
||
});
|
||
});
|
||
|
||
describe("rangeDayCount", () => {
|
||
it("counts inclusive days order-independently", () => {
|
||
expect(rangeDayCount("2026-06-08", "2026-06-12")).toBe(5);
|
||
expect(rangeDayCount("2026-06-12", "2026-06-08")).toBe(5);
|
||
expect(rangeDayCount("2026-06-08", "2026-06-08")).toBe(1);
|
||
});
|
||
});
|
||
|
||
describe("todayIso", () => {
|
||
afterEach(() => {
|
||
vi.useRealTimers();
|
||
});
|
||
|
||
it("uses local calendar day, not UTC ISO date, near midnight", () => {
|
||
// 02:30 UTC is still the previous local evening in Americas (UTC−N).
|
||
vi.useFakeTimers();
|
||
vi.setSystemTime(new Date("2026-08-11T02:30:00.000Z"));
|
||
|
||
const now = new Date();
|
||
const expectedLocal = `${now.getFullYear()}-${pad2(now.getMonth() + 1)}-${pad2(now.getDate())}`;
|
||
const utcSlice = now.toISOString().slice(0, 10);
|
||
|
||
expect(todayIso()).toBe(expectedLocal);
|
||
expect(utcSlice).toBe("2026-08-11");
|
||
|
||
if (now.getTimezoneOffset() > 0) {
|
||
expect(todayIso()).toBe("2026-08-10");
|
||
expect(todayIso()).not.toBe(utcSlice);
|
||
}
|
||
});
|
||
});
|