Browse Source

fix(nc-gui): revise datetime render value logic

pull/5659/head
Wing-Kam Wong 2 years ago
parent
commit
351e07d607
  1. 10
      packages/nc-gui/components/virtual-cell/Formula.vue
  2. 4
      packages/nc-gui/components/virtual-cell/components/utils.ts

10
packages/nc-gui/components/virtual-cell/Formula.vue

@ -25,11 +25,15 @@ const renderResult = (result?: any) => {
return result return result
} }
// convert all date time values to local time // convert all date time values to local time
// the input is always YYYY-MM-DD hh:mm:ss+xx:yy // the datetime is either YYYY-MM-DD hh:mm:ss (xcdb)
return result.replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}:\d{2})\b/g, (d) => { // or YYYY-MM-DD hh:mm:ss+xx:yy (ext)
return result.replace('.000000', '').replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(\+\d{2}:\d{2})?\b/g, (d) => {
// TODO(timezone): retrieve the format from the corresponding column meta // TODO(timezone): retrieve the format from the corresponding column meta
// assume hh:mm at this moment // assume hh:mm at this moment
return dayjs(d).utc().local().format('YYYY-MM-DD HH:mm') return dayjs(d)
.utc(result.indexOf('+') === -1)
.local()
.format('YYYY-MM-DD HH:mm')
}) })
} }
</script> </script>

4
packages/nc-gui/components/virtual-cell/components/utils.ts

@ -2,9 +2,9 @@ import dayjs from 'dayjs'
export const renderValue = (value: string | number | boolean) => { export const renderValue = (value: string | number | boolean) => {
if (!value || typeof value !== 'string') return value if (!value || typeof value !== 'string') return value
return value.replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\+\d{2}:\d{2})\b/g, (d) => { return value.replace(/\b(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})(\+\d{2}:\d{2})?\b/g, (d) => {
// TODO(timezone): retrieve the format from the corresponding column meta // TODO(timezone): retrieve the format from the corresponding column meta
// assume hh:mm at this moment // assume hh:mm at this moment
return dayjs(d).utc().local().format('YYYY-MM-DD HH:mm') return dayjs(d).utc(value.indexOf('+') === -1).local().format('YYYY-MM-DD HH:mm')
}) })
} }

Loading…
Cancel
Save