Browse Source

fix: handle epoch time in date/datepicker cell

re #483

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/894/head
Pranav C 3 years ago
parent
commit
8171a3c804
  1. 11
      packages/nc-gui/components/project/spreadsheet/components/editableCell/datePickerCell.vue
  2. 20
      packages/nc-gui/components/project/spreadsheet/components/editableCell/dateTimePickerCell.vue
  3. 6
      packages/nc-gui/components/project/spreadsheet/components/editableCell/timePickerCell.vue

11
packages/nc-gui/components/project/spreadsheet/components/editableCell/datePickerCell.vue

@ -22,19 +22,10 @@ export default {
},
computed: {
localState: {
/* get() {
return typeof this.value === 'string' ? this.value.replace(/(\d)T(?=\d)/, '$1 ').replace(/\s\d{2}:\d{2}:[\d:.]+z?$/i, '') : (this.value && new Date(this.value))
},
set(val) {
const v = new Date(val)
this.$emit('input', v.toString() === 'Invalid Date' ? '' : new Date(val).toJSON().slice(0, 10))
} */
get() {
if (!this.value) { return this.value }
return dayjs(this.value).format('YYYY-MM-DD')
return (/^\d+$/.test(this.value) ? dayjs(+this.value) : dayjs(this.value)).format('YYYY-MM-DD')
},
set(val) {
this.$emit('input', val && dayjs(val).format('YYYY-MM-DD'))

20
packages/nc-gui/components/project/spreadsheet/components/editableCell/dateTimePickerCell.vue

@ -23,6 +23,7 @@
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
dayjs.extend(utc)
export default {
@ -33,23 +34,14 @@ export default {
computed: {
localState: {
get() {
if (!this.value) { return this.value }
if (!this.value) {
return this.value
}
console.log(this.value, dayjs(this.value).utc().format('YYYY-MM-DD HH:mm'))
return dayjs(this.value).format('YYYY-MM-DD HH:mm')
// todo : time value correction
//
// if (/^\d{6,}$/.test(this.value)) {
// return new Date(+this.value)
// }
//
// return /\dT\d/.test(this.value) ? new Date(this.value.replace(/(\d)T(?=\d)/, '$1 ')) : ((this.value && new Date(this.value)))
return (/^\d+$/.test(this.value) ? dayjs(+this.value) : dayjs(this.value))
.format('YYYY-MM-DD HH:mm')
},
set(val) {
// console.log('dayjs=====', dayjs.utc(val).toString())
// const uVal = val && new Date(val).toISOString().slice(0, 19).replace('T', ' ').replace(/(\d{1,2}:\d{1,2}):\d{1,2}$/, '$1')
// console.log(uVal)
this.$emit('input', val && dayjs(val).format('YYYY-MM-DD HH:mm:ssZ'))
}
},

6
packages/nc-gui/components/project/spreadsheet/components/editableCell/timePickerCell.vue

@ -22,12 +22,6 @@ export default {
},
computed: {
localState: {
// get() {
// return typeof this.value === 'string' ? this.value.replace(/(\d)T(?=\d)/, '$1 ') : this.value
// },
// set(val) {
// this.$emit('input', (new Date(val).toJSON() || '').slice(0, 10) || val)
// }
get() {
if (!this.value) {
return this.value

Loading…
Cancel
Save