From de903a1debacc9218e4871522697855624087d1c Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 27 Apr 2023 17:55:08 +0800 Subject: [PATCH] feat(nc-gui): timezone handling in copied cell data --- .../composables/useMultiSelect/convertCellData.ts | 14 +++++++++++++- .../nc-gui/composables/useMultiSelect/index.ts | 6 +++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts index 33cce2db2a..c766b38a00 100644 --- a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts +++ b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts @@ -7,6 +7,8 @@ import { parseProp } from '#imports' export default function convertCellData( args: { from: UITypes; to: UITypes; value: any; column: ColumnType; appInfo: AppInfo }, isMysql = false, + isSqlite = false, + isXcdbBase = false, ) { const { from, to, value } = args if (from === to && ![UITypes.Attachment, UITypes.Date, UITypes.DateTime, UITypes.Time, UITypes.Year].includes(to)) { @@ -42,7 +44,17 @@ export default function convertCellData( if (!parsedDateTime.isValid()) { throw new Error('Not a valid datetime value') } - return parsedDateTime.format(dateFormat) + if (isXcdbBase) { + if (isMysql) { + return parsedDateTime?.format('YYYY-MM-DD HH:mm:ss') + } else if (isSqlite) { + return parsedDateTime.utc().format('YYYY-MM-DD HH:mm:ss') + } else { + return parsedDateTime.utc().format('YYYY-MM-DD HH:mm:ssZ') + } + } + // TODO(timezone): keep ext db as it is + return parsedDateTime.format(isMysql ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ') } case UITypes.Time: { let parsedTime = dayjs(value) diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index 507cd81f63..d319bc0273 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -52,7 +52,7 @@ export function useMultiSelect( const { appInfo } = useGlobal() - const { isMysql } = useProject() + const { isMysql, isSqlite, isXcdbBase } = useProject() let clipboardContext = $ref<{ value: any; uidt: UITypes } | null>(null) @@ -305,6 +305,8 @@ export function useMultiSelect( appInfo: unref(appInfo), }, isMysql(meta.value?.base_id), + isSqlite(meta.value?.base_id), + isXcdbBase(meta.value?.base_id), ) e.preventDefault() @@ -339,6 +341,8 @@ export function useMultiSelect( appInfo: unref(appInfo), }, isMysql(meta.value?.base_id), + isSqlite(meta.value?.base_id), + isXcdbBase(meta.value?.base_id), ) e.preventDefault() syncCellData?.(activeCell)