| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- import {
- isInvalidIsoDateRange,
- isValidIsoDateYmd,
- } from "@/lib/frontend/search/dateRange";
- /**
- * Zentralisierte Validation fuer Search-Datefilter (ISO YYYY-MM-DD).
- * Gibt ein kleines Fehlerobjekt zurueck (oder null), ohne UI-Abhaengigkeiten.
- *
- * @param {string|null} from
- * @param {string|null} to
- * @returns {{code: string, message: string, details?: any} | null}
- */
- export function getSearchDateRangeValidation(from, to) {
- if (from && !isValidIsoDateYmd(from)) {
- return {
- code: "VALIDATION_SEARCH_DATE",
- message: "Invalid from date",
- details: { from },
- };
- }
- if (to && !isValidIsoDateYmd(to)) {
- return {
- code: "VALIDATION_SEARCH_DATE",
- message: "Invalid to date",
- details: { to },
- };
- }
- if (isInvalidIsoDateRange(from, to)) {
- return {
- code: "VALIDATION_SEARCH_RANGE",
- message: "Invalid date range",
- details: { from, to },
- };
- }
- return null;
- }
|