Browse Source

fix(nc-gui): mysql copy n paste datetime issue

pull/5642/head
Wing-Kam Wong 2 years ago
parent
commit
c3499ee55a
  1. 14
      packages/nc-gui/composables/useMultiSelect/convertCellData.ts
  2. 22
      packages/nc-gui/composables/useMultiSelect/index.ts

14
packages/nc-gui/composables/useMultiSelect/convertCellData.ts

@ -39,10 +39,22 @@ export default function convertCellData(
return parsedDate.format('YYYY-MM-DD') return parsedDate.format('YYYY-MM-DD')
} }
case UITypes.DateTime: { case UITypes.DateTime: {
const parsedDateTime = dayjs(value) let parsedDateTime = dayjs(value)
if (!parsedDateTime.isValid()) { if (!parsedDateTime.isValid()) {
throw new Error('Not a valid datetime value') 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) { if (isXcdbBase) {
// convert back to utc // convert back to utc
// e.g. (mysql) 2023-05-11 12:00:00+00:00 -> 2023-05-11 12:00:00 // e.g. (mysql) 2023-05-11 12:00:00+00:00 -> 2023-05-11 12:00:00

22
packages/nc-gui/composables/useMultiSelect/index.ts

@ -117,18 +117,30 @@ export function useMultiSelect(
} }
if (columnObj.uidt === UITypes.DateTime) { 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) let d = dayjs(textToCopy)
if (!d.isValid()) { if (!d.isValid()) {
const isMySQL = isMysql(columnObj.base_id)
// insert a datetime value, copy the value without refreshing // insert a datetime value, copy the value without refreshing
// e.g. textToCopy = 2023-05-12T03:49:25.000Z // e.g. textToCopy = 2023-05-12T03:49:25.000Z
// feed custom parse format // feed custom parse format
d = dayjs(textToCopy, isMySQL ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ') 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 // users can change the datetime format in UI
// `textToCopy` would be always in YYYY-MM-DD HH:mm:ss(Z / +xx:yy) format // `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 // therefore, here we reformat to the correct datetime format based on the meta

Loading…
Cancel
Save