Browse Source

feat(gui-v2): add date function for formulas

pull/2998/head
Wing-Kam Wong 2 years ago
parent
commit
d94adf038c
  1. 26
      packages/nc-gui-v2/utils/dateTimeUtils.ts

26
packages/nc-gui-v2/utils/dateTimeUtils.ts

@ -1,4 +1,6 @@
import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
dayjs.extend(customParseFormat)
export const timeAgo = (date: any) => {
return dayjs.utc(date).fromNow()
@ -18,3 +20,27 @@ export const handleTZ = (val: any) => {
},
)
}
export const dateFormat = [
'DD-MM-YYYY',
'MM-DD-YYYY',
'YYYY-MM-DD',
'DD/MM/YYYY',
'MM/DD/YYYY',
'YYYY/MM/DD',
'DD MM YYYY',
'MM DD YYYY',
'YYYY MM DD',
]
export function validateDateFormat(v: string) {
return dateFormat.includes(v)
}
export function validateDateWithUnknownFormat(v: string) {
let res = 0
for (const format of dateFormat) {
res |= dayjs(v, format, true).isValid() as any
}
return res
}

Loading…
Cancel
Save