Skip to content

Commit

Permalink
fix: converting without a format in case the conversion doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-w committed May 20, 2024
1 parent 0dad34a commit bb699da
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/core/src/models/field/derivate/date.field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ export class DateFieldCore extends FieldCore {

return this.item2String(cellValue as string);
}
private defaultTzFormat(value: string) {
try {
const formatValue = dayjs.tz(value, this.options.formatting.timeZone);
if (!formatValue.isValid()) return null;
return formatValue.toISOString();
} catch (e) {
return null;
}
}

convertStringToCellValue(value: string): string | null {
if (this.isLookup) {
Expand All @@ -66,12 +75,13 @@ export class DateFieldCore extends FieldCore {
const format =
this.options.formatting.date +
(hasTime && this.options.formatting.time ? ' ' + this.options.formatting.time : '');

try {
const formatValue = dayjs.tz(value, format, this.options.formatting.timeZone);
if (!formatValue.isValid()) return null;
return formatValue.toISOString();
} catch (e) {
return null;
return this.defaultTzFormat(value);
}
}

Expand Down

0 comments on commit bb699da

Please sign in to comment.