Browse Source

fix(nc-gui): revise datetime picker rendering logic ...

pull/5601/head
Wing-Kam Wong 2 years ago
parent
commit
63783fd992
  1. 24
      packages/nc-gui/components/cell/DateTimePicker.vue

24
packages/nc-gui/components/cell/DateTimePicker.vue

@ -18,9 +18,10 @@ import {
interface Props {
modelValue?: string | null
isPk?: boolean
isUpdateOutside: Record<string, boolean>
}
const { modelValue, isPk } = defineProps<Props>()
const { modelValue, isPk, isUpdateOutside } = defineProps<Props>()
const emit = defineEmits(['update:modelValue'])
@ -44,7 +45,7 @@ const dateTimeFormat = $computed(() => {
return `${dateFormat} ${timeFormat}`
})
let localModelValue = $ref(modelValue ? dayjs(modelValue).utc(true).local() : undefined)
let localModelValue = modelValue ? dayjs(modelValue).utc(true).local() : undefined
let localState = $computed({
get() {
@ -57,10 +58,28 @@ let localState = $computed({
return undefined
}
// if cdf is defined, that means the value is auto-generated
// hence, show the local time
if (column?.value?.cdf) {
return dayjs(modelValue).utc(true).local()
}
// cater copy and paste
// when copying a datetime cell, the copied value would be local time
// when pasting a datetime cell, UTC (xcdb) will be saved in DB
// we convert back to local time
if (column.value.title! in (isUpdateOutside ?? {})) {
localModelValue = dayjs(modelValue).utc().local()
return localModelValue
}
// if localModelValue is defined, show localModelValue instead
// localModelValue is set in setter below
if (localModelValue) {
return localModelValue
}
// empty cell - use modelValue in local time
return dayjs(modelValue).utc(true).local()
},
set(val?: dayjs.Dayjs) {
@ -71,6 +90,7 @@ let localState = $computed({
if (val.isValid()) {
const formattedValue = dayjs(val?.format(isMysql(column.value.base_id) ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm:ssZ'))
// setting localModelValue to cater NOW function in date picker
localModelValue = formattedValue
emit('update:modelValue', formattedValue)
}

Loading…
Cancel
Save