diff --git a/packages/nc-gui/components/virtual-cell/Formula.vue b/packages/nc-gui/components/virtual-cell/Formula.vue index 4334648ade..07444cefd7 100644 --- a/packages/nc-gui/components/virtual-cell/Formula.vue +++ b/packages/nc-gui/components/virtual-cell/Formula.vue @@ -25,11 +25,15 @@ const renderResult = (result?: any) => { return result } // convert all date time values to local time - // the input is always YYYY-MM-DD hh:mm:ss+xx:yy - return result.replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}:\d{2})\b/g, (d) => { + // the datetime is either YYYY-MM-DD hh:mm:ss (xcdb) + // or YYYY-MM-DD hh:mm:ss+xx:yy (ext) + return result.replace('.000000', '').replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(\+\d{2}:\d{2})?\b/g, (d) => { // TODO(timezone): retrieve the format from the corresponding column meta // assume hh:mm at this moment - return dayjs(d).utc().local().format('YYYY-MM-DD HH:mm') + return dayjs(d) + .utc(result.indexOf('+') === -1) + .local() + .format('YYYY-MM-DD HH:mm') }) } diff --git a/packages/nc-gui/components/virtual-cell/components/utils.ts b/packages/nc-gui/components/virtual-cell/components/utils.ts index 82235c1962..6250bf2275 100644 --- a/packages/nc-gui/components/virtual-cell/components/utils.ts +++ b/packages/nc-gui/components/virtual-cell/components/utils.ts @@ -2,9 +2,9 @@ import dayjs from 'dayjs' export const renderValue = (value: string | number | boolean) => { if (!value || typeof value !== 'string') return value - return value.replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}:\d{2})\b/g, (d) => { + return value.replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(\+\d{2}:\d{2})?\b/g, (d) => { // TODO(timezone): retrieve the format from the corresponding column meta // assume hh:mm at this moment - return dayjs(d).utc().local().format('YYYY-MM-DD HH:mm') + return dayjs(d).utc(value.indexOf('+') === -1).local().format('YYYY-MM-DD HH:mm') }) }