import { z } from "zod"; import { bankMonth } from "./form-validation"; const calendarDate = z.iso.date(); const ISO_DATE_LENGTH = 10; function bankPeriod(parameters: URLSearchParams) { const month = bankMonth(parameters.get("month")); const monthEnd = new Date(`${month}-01T00:00:00Z`); monthEnd.setUTCMonth(monthEnd.getUTCMonth() + 1, 0); const from = parameters.get("from"); const to = parameters.get("to"); return from && to && calendarDate.safeParse(from).success && calendarDate.safeParse(to).success && from >= "0001-01-01" && from <= to ? { from, to } : { from: `${month}-01`, to: monthEnd.toISOString().slice(0, ISO_DATE_LENGTH), }; } export { bankPeriod };