Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: broken date format logic

mertmit5c895c43a42a
diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts
index cc75cbd27e..2543eefb61 100644
--- a/packages/nocodb/src/db/BaseModelSqlv2.ts
+++ b/packages/nocodb/src/db/BaseModelSqlv2.ts
@@ -5658,13 +5658,13 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
for (const lookedUpAttachment of Array.isArray(attachment)
? attachment
: [attachment]) {
- const thumbnails =
- this.prepareAttachmentForSigning(lookedUpAttachment);
- if (
- lookedUpAttachment &&
- (lookedUpAttachment.path || lookedUpAttachment.url)
- ) {
- allAttachments.push(lookedUpAttachment);
+ const thumbnails =
+ this.prepareAttachmentForSigning(lookedUpAttachment);
+ if (
+ lookedUpAttachment &&
+ (lookedUpAttachment.path || lookedUpAttachment.url)
+ ) {
+ allAttachments.push(lookedUpAttachment);
allThumbnails.push(...thumbnails);
}
}
@@ -6069,7 +6069,7 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
if (col.uidt === UITypes.Date) {
const dateFormat = col.meta?.date_format;
if (dateFormat) {
- d[col.title] = dayjs(d[col.title], dateFormat).format(dateFormat);
+ d[col.id] = dayjs(d[col.id]).format(dateFormat);
}
continue;
}
diff --git a/packages/nocodb/src/db/field-handler/handlers/date-time/date-time.general.handler.ts b/packages/nocodb/src/db/field-handler/handlers/date-time/date-time.general.handler.ts
index dd46ff4b1a..18e097c798 100644
--- a/packages/nocodb/src/db/field-handler/handlers/date-time/date-time.general.handler.ts
+++ b/packages/nocodb/src/db/field-handler/handlers/date-time/date-time.general.handler.ts
@@ -78,12 +78,20 @@ export class DateTimeGeneralHandler extends GenericFieldHandler {
metaService?: MetaService;
};
}) {
+ // Allow null/undefined/empty values
+ if (
+ params.value === null ||
+ params.value === undefined ||
+ params.value === ''
+ ) {
+ return { value: null };
+ }
+
let dayjsUtcValue: dayjs.Dayjs;
if (
- params.value &&
- (params.value instanceof Date ||
- typeof params.value === 'string' ||
- typeof params.value === 'number')
+ params.value instanceof Date ||
+ typeof params.value === 'string' ||
+ typeof params.value === 'number'
) {
if (params.value instanceof Date) {
dayjsUtcValue = dayjs(params.value).utc();
@@ -106,7 +114,7 @@ export class DateTimeGeneralHandler extends GenericFieldHandler {
dayjsUtcValue = dayjs.unix(params.value).utc();
}
}
- if (!dayjsUtcValue.isValid()) {
+ if (!dayjsUtcValue || !dayjsUtcValue.isValid()) {
NcError.invalidValueForField({
value: params.value,
column: params.column.title,
diff --git a/packages/nocodb/src/db/field-handler/handlers/date/date.general.handler.ts b/packages/nocodb/src/db/field-handler/handlers/date/date.general.handler.ts
index 2df54d049f..49efa3e730 100644
--- a/packages/nocodb/src/db/field-handler/handlers/date/date.general.handler.ts
+++ b/packages/nocodb/src/db/field-handler/handlers/date/date.general.handler.ts
@@ -17,12 +17,20 @@ export class DateGeneralHandler extends DateTimeGeneralHandler {
metaService?: MetaService;
};
}): Promise<{ value: any }> {
+ // Allow null/undefined values
+ if (
+ ncIsUndefined(params.value) ||
+ params.value === null ||
+ params.value === ''
+ ) {
+ return { value: params.value };
+ }
+
let dayjsUtcValue: dayjs.Dayjs;
if (
- !ncIsUndefined(params.value) &&
- (params.value instanceof Date ||
- typeof params.value === 'number' ||
- typeof params.value === 'string')
+ params.value instanceof Date ||
+ typeof params.value === 'number' ||
+ typeof params.value === 'string'
) {
if (params.value instanceof Date) {
dayjsUtcValue = dayjs(params.value).utc();
@@ -38,7 +46,7 @@ export class DateGeneralHandler extends DateTimeGeneralHandler {
dayjsUtcValue = dayjs.unix(params.value).utc();
}
}
- if (!dayjsUtcValue.isValid()) {
+ if (!dayjsUtcValue || !dayjsUtcValue.isValid()) {
NcError.invalidValueForField({
value: params.value,
column: params.column.title,
diff --git a/packages/nocodb/tests/unit/rest/tests/dataApiV3/list-and-crud.test.ts b/packages/nocodb/tests/unit/rest/tests/dataApiV3/list-and-crud.test.ts
index e967c060f3..b72dfde1e9 100644
--- a/packages/nocodb/tests/unit/rest/tests/dataApiV3/list-and-crud.test.ts
+++ b/packages/nocodb/tests/unit/rest/tests/dataApiV3/list-and-crud.test.ts
@@ -567,7 +567,7 @@ describe('dataApiV3', () => {
// update record with Id 801 to 804
const updatedRecord = {
- Date: '2022-04-25',
+ Date: '2022/04/25',
DateTime: '2022-04-25 08:30:00+00:00',
};
const updatedRecords = [801, 802, 803, 804].map((id) => ({