From 66669b117dd966d3ef05a95d4daeb06faf2db4b6 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 15 May 2023 18:01:39 +0800 Subject: [PATCH] fix(nocodb): multiple datetimes in formula --- packages/nocodb/src/db/BaseModelSqlv2.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 5ba8bac7e8..f09661afa8 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -3263,14 +3263,15 @@ class BaseModelSqlv2 { for (const col of dateTimeColumns) { if (d[col.title]) { if (col.uidt === UITypes.Formula) { - if (dayjs(d[col.title]).isValid()) { - // d[col.title] will be in UTC without timezone - // append the timezone info here - // e.g. 2021-12-30 04:00:00 -> 2021-12-30 04:00:00+00:00 - d[col.title] = dayjs(d[col.title]) - .utc(true) - .format('YYYY-MM-DD HH:mm:ssZ'); - } + d[col.title] = d[col.title].replace( + /\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\b/g, + (match) => { + // d[col.title] will be in UTC without timezone + // append the timezone info here + // e.g. 2021-12-30 04:00:00 -> 2021-12-30 04:00:00+00:00 + return dayjs(match).utc(true).format('YYYY-MM-DD HH:mm:ssZ'); + }, + ); continue; }