mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-21 03:42:16 +00:00
fix: Allow Date/Luxon objects and additional formats in DateTime validation (#8525)
This commit is contained in:
@@ -52,6 +52,17 @@ export const tryToParseBoolean = (value: unknown): value is boolean => {
|
||||
};
|
||||
|
||||
export const tryToParseDateTime = (value: unknown): DateTime => {
|
||||
if (value instanceof DateTime && value.isValid) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value instanceof Date) {
|
||||
const fromJSDate = DateTime.fromJSDate(value);
|
||||
if (fromJSDate.isValid) {
|
||||
return fromJSDate;
|
||||
}
|
||||
}
|
||||
|
||||
const dateString = String(value).trim();
|
||||
|
||||
// Rely on luxon to parse different date formats
|
||||
@@ -72,6 +83,11 @@ export const tryToParseDateTime = (value: unknown): DateTime => {
|
||||
return sqlDate;
|
||||
}
|
||||
|
||||
const parsedDateTime = DateTime.fromMillis(Date.parse(dateString));
|
||||
if (parsedDateTime.isValid) {
|
||||
return parsedDateTime;
|
||||
}
|
||||
|
||||
throw new ApplicationError('Value is not a valid date', { extra: { dateString } });
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user