diff --git a/packages/survey-ui/src/components/elements/date.tsx b/packages/survey-ui/src/components/elements/date.tsx index 4327feb3b8..faaa568a38 100644 --- a/packages/survey-ui/src/components/elements/date.tsx +++ b/packages/survey-ui/src/components/elements/date.tsx @@ -19,8 +19,8 @@ function parseValueToDate(value: string, format: DateStorageFormat): Date | unde if (!trimmed) return undefined; const parts = trimmed.split("-"); if (parts.length !== 3) return undefined; + if (parts.some((p) => !/^\d+$/.test(p))) return undefined; const nums = parts.map((p) => Number.parseInt(p, 10)); - if (nums.some(Number.isNaN)) return undefined; const useIso = ISO_FIRST_CHARS.test(trimmed); const effective = useIso ? DEFAULT_DATE_STORAGE_FORMAT : format; const order = DATE_STORAGE_FORMATS[effective].parseOrder; diff --git a/packages/surveys/src/lib/date-format.ts b/packages/surveys/src/lib/date-format.ts index 3dca196b1f..87585134f1 100644 --- a/packages/surveys/src/lib/date-format.ts +++ b/packages/surveys/src/lib/date-format.ts @@ -60,6 +60,11 @@ export function parseDateByFormat( * Try to parse a date string using each known storage format in order. * Use when the storage format is unknown (e.g. recall placeholders). * + * Ambiguity: Values like "03-05-2024" can be March 5th (M-d-y) or May 3rd (d-M-y). + * Formats are tried in DATE_STORAGE_FORMATS_LIST order (M-d-y, then d-M-y, then y-M-d); + * the first successful parse is returned. M-d-y is preferred when format metadata is + * unavailable so that common US-style input is accepted first. + * * @param value - Stored date string * @returns Parsed Date or null if no format matched */ diff --git a/packages/surveys/src/lib/logic.ts b/packages/surveys/src/lib/logic.ts index ee6eadb64a..e0e5e2e665 100644 --- a/packages/surveys/src/lib/logic.ts +++ b/packages/surveys/src/lib/logic.ts @@ -42,7 +42,13 @@ function compareDateOperands( }); return false; } - if (rightDate === null) return false; + if (rightDate === null) { + console.warn(`[logic] ${operator}: could not parse right date`, { + elementId: rightField.id, + value: rightValue, + }); + return false; + } return compare(leftDate, rightDate); } diff --git a/packages/types/surveys/date-formats.ts b/packages/types/surveys/date-formats.ts index 2b1576a9c7..5ace311da2 100644 --- a/packages/types/surveys/date-formats.ts +++ b/packages/types/surveys/date-formats.ts @@ -53,5 +53,9 @@ export const DATE_STORAGE_FORMATS: Record