// A finance dashboard: each sale filed under its fiscal year and quarter, a store's 4-5-4 retail periods, and ISO weeks for the warehouse.
//
//   quillo run fiscal_calendar.qwe      then open http://localhost:8080/fiscal

use "fiscal_calendar.qwer"

route GET /fiscal {
    {
        us_government: fiscal_year("2026-10-29", 10)?,
        uk_government: fiscal_year("2026-04-05", 4)?.label,
        calendar_year: fiscal_year("2026-10-29", 1)?.quarter_label,
        // The NRF retail calendar: 4-5-4, the year ending on the Saturday nearest the end of January.
        nrf: fiscal_retail("2026-10-29", "4-5-4", 1, "Sat", "nearest")?,
        nrf_53_weeks: fiscal_retail("2023-12-31", "4-5-4", 1, "Sat", "nearest")?.weeks_in_year,
        // Apple's: 4-4-5, ending on the last Saturday of September.
        apple: fiscal_retail("2026-10-29", "4-4-5", 9, "Sat", "last")?.fiscal_year,
        iso: fiscal_iso_week("2026-10-29")?,
        iso_new_year: fiscal_iso_week("2027-01-01")?.text,
        bad: fiscal_retail("2026-10-29", "4-4-4", 1, "Sat", "last").error,
    }
}

route GET /periods = fiscal_retail_periods("2026-10-29", "4-5-4", 1, "Sat", "nearest")?
