import { describe, it, expect } from "vitest";
import { parseRelativeDate } from "../relative-date.js";
// Frozen reference: Wednesday, 2026-05-20 14:30 UTC.
const REF = new Date("2026-05-20T14:30:00Z");
function iso(d) {
    return d.toISOString();
}
describe("parseRelativeDate", () => {
    it("returns null for empty / invalid input", () => {
        expect(parseRelativeDate("", REF)).toBeNull();
        expect(parseRelativeDate("no date here", REF)).toBeNull();
        expect(parseRelativeDate("anything", new Date("invalid"))).toBeNull();
    });
    it("parses literal days against reference", () => {
        expect(iso(parseRelativeDate("yesterday we met", REF).date)).toBe("2026-05-19T00:00:00.000Z");
        expect(iso(parseRelativeDate("today is busy", REF).date)).toBe("2026-05-20T00:00:00.000Z");
        expect(iso(parseRelativeDate("tomorrow at noon", REF).date)).toBe("2026-05-21T00:00:00.000Z");
    });
    it("parses last/next/this weekday", () => {
        // Ref is Wed 2026-05-20. Last Tuesday is 2026-05-19 (one day ago).
        expect(iso(parseRelativeDate("last Tuesday", REF).date)).toBe("2026-05-19T00:00:00.000Z");
        // Last Wednesday is the prior week (2026-05-13), not today.
        expect(iso(parseRelativeDate("last Wednesday", REF).date)).toBe("2026-05-13T00:00:00.000Z");
        // Next Friday is 2026-05-22.
        expect(iso(parseRelativeDate("next Friday", REF).date)).toBe("2026-05-22T00:00:00.000Z");
        // This Monday is 2026-05-18 (start of this week).
        expect(iso(parseRelativeDate("this Monday", REF).date)).toBe("2026-05-18T00:00:00.000Z");
        // Short forms.
        expect(iso(parseRelativeDate("last Fri", REF).date)).toBe("2026-05-15T00:00:00.000Z");
    });
    it("parses N units ago", () => {
        expect(iso(parseRelativeDate("two weeks ago", REF).date)).toBe("2026-05-06T00:00:00.000Z");
        expect(iso(parseRelativeDate("3 days ago", REF).date)).toBe("2026-05-17T00:00:00.000Z");
        expect(iso(parseRelativeDate("a month ago", REF).date)).toBe("2026-04-20T00:00:00.000Z");
        expect(iso(parseRelativeDate("one year ago", REF).date)).toBe("2025-05-20T00:00:00.000Z");
    });
    it("parses holiday anchors", () => {
        expect(iso(parseRelativeDate("this Christmas", REF).date)).toBe("2026-12-25T00:00:00.000Z");
        expect(iso(parseRelativeDate("Christmas plans", REF).date)).toBe("2026-12-25T00:00:00.000Z");
        expect(iso(parseRelativeDate("this New Year", REF).date)).toBe("2026-01-01T00:00:00.000Z");
        expect(iso(parseRelativeDate("New Year's Day", REF).date)).toBe("2026-01-01T00:00:00.000Z");
    });
    it("parses fiscal quarters with explicit year", () => {
        expect(iso(parseRelativeDate("Q1 2025", REF).date)).toBe("2025-01-01T00:00:00.000Z");
        expect(iso(parseRelativeDate("Q3 2024", REF).date)).toBe("2024-07-01T00:00:00.000Z");
        expect(iso(parseRelativeDate("Q4 2026", REF).date)).toBe("2026-10-01T00:00:00.000Z");
        // Two-digit year.
        expect(iso(parseRelativeDate("Q2 25", REF).date)).toBe("2025-04-01T00:00:00.000Z");
    });
    it("parses fiscal quarters with relative year", () => {
        expect(iso(parseRelativeDate("Q3 last year", REF).date)).toBe("2025-07-01T00:00:00.000Z");
        expect(iso(parseRelativeDate("Q1 this year", REF).date)).toBe("2026-01-01T00:00:00.000Z");
        expect(iso(parseRelativeDate("Q4 next year", REF).date)).toBe("2027-10-01T00:00:00.000Z");
    });
    it("returns null for recurring forms", () => {
        expect(parseRelativeDate("every other Friday", REF)).toBeNull();
        expect(parseRelativeDate("every Tuesday", REF)).toBeNull();
        expect(parseRelativeDate("every week", REF)).toBeNull();
    });
    it("reports the matched form", () => {
        expect(parseRelativeDate("yesterday", REF).form).toBe("literal-day");
        expect(parseRelativeDate("last Tuesday", REF).form).toBe("weekday");
        expect(parseRelativeDate("two weeks ago", REF).form).toBe("ago");
        expect(parseRelativeDate("Christmas", REF).form).toBe("holiday");
        expect(parseRelativeDate("Q1 2025", REF).form).toBe("quarter");
    });
});
//# sourceMappingURL=relative-date.test.js.map