import { calendarDate } from "@/shared/lib"; const DATE_PART_COUNT = 3; type IncomePeriod = { from: string; to: string }; function formatDraftDate(value: string): string { const [year, month, day] = value.split("-", DATE_PART_COUNT); return `${day}.${month}.${year}`; } function parseDraftDate(value: string): null | string { if (!/^\d{2}\.\d{2}\.\d{4}$/.test(value)) return null; const [day, month, year] = value.split(".", DATE_PART_COUNT); const date = `${year}-${month}-${day}`; return calendarDate.safeParse(date).success ? date : null; } export { formatDraftDate, type IncomePeriod as IncomeForm, type IncomePeriod, parseDraftDate, };