Browse Source

refactor(nc-gui): move the parse string date logic to dateTimeUtil

pull/4135/head
Wing-Kam Wong 2 years ago
parent
commit
b6f81de2b3
  1. 10
      packages/nc-gui/components/template/Editor.vue
  2. 10
      packages/nc-gui/utils/dateTimeUtils.ts

10
packages/nc-gui/components/template/Editor.vue

@ -19,6 +19,7 @@ import {
message,
nextTick,
onMounted,
parseStringDate,
reactive,
ref,
useI18n,
@ -244,12 +245,7 @@ function remapColNames(batchData: any[], columns: ColumnType[]) {
dateFormat = getDateFormat(d)
dateFormatMap[col.key] = dateFormat
}
const dayjsObj = dayjs(d)
if (dayjsObj.isValid()) {
d = dayjsObj.format('YYYY-MM-DD')
} else {
d = dayjs(d, dateFormat).format('YYYY-MM-DD')
}
d = parseStringDate(d, dateFormat)
} else if (col.uidt === UITypes.DateTime && d) {
d = dayjs(data[key]).utc().format('YYYY-MM-DD HH:mm')
}
@ -406,6 +402,8 @@ async function importTemplate() {
if (input === '') {
input = null
}
} else if (v.uidt === UITypes.Date) {
input = parseStringDate(input, v.meta.date_format)
}
res[col.destCn] = input
}

10
packages/nc-gui/utils/dateTimeUtils.ts

@ -51,3 +51,13 @@ export function getDateFormat(v: string) {
}
return 'YYYY/MM/DD'
}
export function parseStringDate(v: string, dateFormat: string) {
const dayjsObj = dayjs(v)
if (dayjsObj.isValid()) {
v = dayjsObj.format('YYYY-MM-DD')
} else {
v = dayjs(v, dateFormat).format('YYYY-MM-DD')
}
return v
}

Loading…
Cancel
Save