From 24879536100f41de95749fc52906d138f78f146f Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 17 May 2023 09:45:03 +0530 Subject: [PATCH] feat(nocodb): handle datetime in formula aliasToColumn --- .../src/db/formulav2/formulaQueryBuilderv2.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts index e34e503cf5..312eb169ee 100644 --- a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts +++ b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts @@ -537,6 +537,33 @@ async function _formulaQueryBuilder( }; }; break; + case UITypes.DateTime: + if (knex.clientType().startsWith('mysql')) { + aliasToColumn[col.id] = async (): Promise => { + return { + builder: knex.raw( + `CONVERT_TZ(??, @@GLOBAL.time_zone, '+00:00')`, + [col.column_name], + ), + }; + }; + } else if ( + knex.clientType() === 'pg' && + col.dt !== 'timestamp with time zone' + ) { + aliasToColumn[col.id] = async (): Promise => { + return { + builder: knex.raw( + `?? AT TIME ZONE CURRENT_SETTING('timezone') AT TIME ZONE 'UTC'`, + [col.column_name], + ), + }; + }; + } else { + aliasToColumn[col.id] = () => + Promise.resolve({ builder: col.column_name }); + } + break; default: aliasToColumn[col.id] = () => Promise.resolve({ builder: col.column_name });