diff --git a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts index 4171c05189..f181b24ce9 100644 --- a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts +++ b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts @@ -39,10 +39,22 @@ export default function convertCellData( return parsedDate.format('YYYY-MM-DD') } case UITypes.DateTime: { - const parsedDateTime = dayjs(value) + let parsedDateTime = dayjs(value) if (!parsedDateTime.isValid()) { throw new Error('Not a valid datetime value') } + + if (isMysql && !dayjs.isDayjs(value)) { + if (value.indexOf('+') === -1) { + // insert a datatime cell -> copy and paste -> copy again -> paste + // e.g. value = 2023-05-12 08:06:54 + if (value.slice(-1) !== 'Z') { + // e.g. 2023-05-11 12:00:00 -> 2023-05-11 12:00:00Z0 + parsedDateTime = dayjs(value + 'Z') + } + } + } + if (isXcdbBase) { // convert back to utc // e.g. (mysql) 2023-05-11 12:00:00+00:00 -> 2023-05-11 12:00:00 diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index 2627662735..743602b181 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -117,18 +117,30 @@ export function useMultiSelect( } if (columnObj.uidt === UITypes.DateTime) { + // remove `"` + // e.g. "2023-05-12T08:03:53.000Z" -> 2023-05-12T08:03:53.000Z + textToCopy = textToCopy.replace(/["']/g, '') + + const isMySQL = isMysql(columnObj.base_id) + if (isMySQL) { + if (textToCopy.indexOf('+') === -1) { + // insert a datatime cell -> copy and paste -> copy again + if (textToCopy.slice(-1) !== 'Z') { + // e.g. 2023-05-11 12:00:00 -> 2023-05-11 12:00:00Z + textToCopy += 'Z' + } + } + } + let d = dayjs(textToCopy) + if (!d.isValid()) { - const isMySQL = isMysql(columnObj.base_id) // insert a datetime value, copy the value without refreshing // e.g. textToCopy = 2023-05-12T03:49:25.000Z // feed custom parse format d = dayjs(textToCopy, isMySQL ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ') - if (isMySQL) { - // convert to local time - e.g. 2023-05-12T11:49:25+08:00 - d = dayjs(d).utc(true).local() - } } + // users can change the datetime format in UI // `textToCopy` would be always in YYYY-MM-DD HH:mm:ss(Z / +xx:yy) format // therefore, here we reformat to the correct datetime format based on the meta