From 205a2a21909dc32fb3c32ad87296a27534187086 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 21 Apr 2023 17:00:07 +0800 Subject: [PATCH] feat(nocodb): revise type parser for timestamp --- packages/nocodb-nest/src/db/CustomKnex.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/nocodb-nest/src/db/CustomKnex.ts b/packages/nocodb-nest/src/db/CustomKnex.ts index 4ca7e0eb51..69d765bf21 100644 --- a/packages/nocodb-nest/src/db/CustomKnex.ts +++ b/packages/nocodb-nest/src/db/CustomKnex.ts @@ -1,16 +1,21 @@ import { Knex, knex } from 'knex'; import { SnowflakeClient } from 'nc-help'; -import { types } from 'pg'; +import pg, { types } from 'pg'; +import dayjs from 'dayjs'; import Filter from '../models/Filter'; import type { FilterType } from 'nocodb-sdk'; import type { BaseModelSql } from './BaseModelSql'; +pg.defaults.parseInputDatesAsUTC = true; + // override parsing date column to Date() types.setTypeParser(1082, (val) => val); // override timestamp -types.setTypeParser(1114, (val) => { - return new Date(val + '+0000'); -}); +for (const oid of [1114, 1184]) { + types.setTypeParser(oid, (val) => { + return dayjs(val).utc(true).local().format('YYYY-MM-DD HH:mm:ssZ'); + }); +} const opMappingGen = { eq: '=',