import { describe, expect, it } from "vitest"; import { currentFyStartYear, fyLabel, fyRange, fyStartYear, monthOf, todayIst, FY_MONTHS } from "./fiscal"; describe("financial year", () => { it("starts on 1 April", () => { expect(fyStartYear("2026-03-31")).toBe(2025); expect(fyStartYear("2026-04-01")).toBe(2026); expect(fyStartYear("2026-12-31")).toBe(2026); expect(fyStartYear("2027-01-01")).toBe(2026); }); it("rejects things that are not ISO dates", () => { expect(fyStartYear("")).toBeNull(); expect(fyStartYear("01/04/2026")).toBeNull(); expect(fyStartYear("2026-13-01")).toBeNull(); expect(monthOf("2026-00-10")).toBeNull(); expect(monthOf("2026-07-10")).toBe(7); }); it("labels and ranges", () => { expect(fyLabel(2025)).toBe("FY 2025-26"); expect(fyLabel(2099)).toBe("FY 2099-00"); expect(fyRange(2025)).toEqual({ from: "2025-04-01", to: "2026-03-31" }); }); it("lists months April to March", () => { expect(FY_MONTHS.map((m) => m.month)).toEqual([4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3]); expect(FY_MONTHS[0].label).toBe("April"); }); it("uses IST for now, not the machine time zone", () => { // 20:00 UTC on 31 March is already 01:30 on 1 April in India: a new financial year. const now = new Date("2026-03-31T20:00:00Z"); expect(todayIst(now)).toBe("2026-04-01"); expect(currentFyStartYear(now)).toBe(2026); // 18:29 UTC is still 23:59 on 31 March in India. expect(currentFyStartYear(new Date("2026-03-31T18:29:00Z"))).toBe(2025); }); });