mirror of
https://github.com/formbricks/formbricks.git
synced 2026-03-17 08:21:39 -05:00
chore: assorted fixes
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,5 +53,9 @@ export const DATE_STORAGE_FORMATS: Record<TSurveyDateStorageFormat, DateFormatDe
|
||||
},
|
||||
};
|
||||
|
||||
/** All format ids as an array (for iteration, e.g. try-parse or dropdowns). */
|
||||
/**
|
||||
* All format ids as an array (for iteration, e.g. dropdowns or try-parse).
|
||||
* When used for try-parse without format metadata, the first matching format wins;
|
||||
* order is M-d-y, d-M-y, y-M-d (see parseDateWithFormats in @formbricks/surveys).
|
||||
*/
|
||||
export const DATE_STORAGE_FORMATS_LIST: TSurveyDateStorageFormat[] = [...DATE_STORAGE_FORMAT_IDS];
|
||||
|
||||
Reference in New Issue
Block a user