From b3177a19334200d688f290535a7df186d7df6a7e Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 10 May 2023 17:14:51 +0800 Subject: [PATCH] fix(nocodb): revise convertDateFormat logic --- packages/nocodb/src/db/BaseModelSqlv2.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 97e740a31b..4afa19d12d 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -3217,8 +3217,11 @@ class BaseModelSqlv2 { d: Record, ) { if (d) { - dateTimeColumns.forEach((col) => { + for (const col of dateTimeColumns) { if (d[col.title]) { + if (col.dt === 'timestamp with time zone') { + continue; + } // e.g. 01.01.2022 10:00:00+05:30 -> 2022-01-01 04:30:00+00:00 // e.g. 2023-05-09 11:41:49 -> 2023-05-09 11:41:49+00:00 d[col.title] = dayjs(d[col.title]) @@ -3227,7 +3230,7 @@ class BaseModelSqlv2 { // show the timezone even for Mysql .format('YYYY-MM-DD HH:mm:ssZ'); } - }); + } } return d; } @@ -3237,9 +3240,13 @@ class BaseModelSqlv2 { isXcdbBase: BoolType, childTable?: Model, ) { + // skip for the following cases + if (this.isSqlite && !isXcdbBase) { + return data; + } // Show the date time in UTC format in API response // e.g. 2022-01-01 04:30:00+00:00 - if (isXcdbBase && data) { + if (data) { const dateTimeColumns = ( childTable ? childTable.columns : this.model.columns ).filter((c) => c.uidt === UITypes.DateTime); @@ -3258,7 +3265,7 @@ class BaseModelSqlv2 { // trigger before insert / update // TODO: refactor - maybe there is a better approach private async setUtcTimezoneForPg() { - if (this.isPg && (await this.isXcdbBase())) { + if (this.isPg) { await this.dbDriver.raw(`SET TIME ZONE 'UTC'`); } }