mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
959 B
45 lines
959 B
3 years ago
|
import dayjs from 'dayjs'
|
||
|
|
||
2 years ago
|
export const timeAgo = (date: any) => {
|
||
2 years ago
|
return dayjs.utc(date).fromNow()
|
||
|
}
|
||
|
|
||
2 years ago
|
export const dateFormats = [
|
||
|
'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',
|
||
|
]
|
||
|
|
||
3 years ago
|
export const handleTZ = (val: any) => {
|
||
|
if (!val) {
|
||
|
return
|
||
|
}
|
||
|
if (typeof val !== 'string') {
|
||
|
return val
|
||
|
}
|
||
|
return val.replace(
|
||
|
/((?:-?(?:[1-9][0-9]*)?[0-9]{4})-(?:1[0-2]|0[1-9])-(?:3[01]|0[1-9]|[12][0-9])T(?:2[0-3]|[01][0-9]):(?:[0-5][0-9]):(?:[0-5][0-9])(?:\.[0-9]+)?(?:Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9]))/g,
|
||
|
(i, v) => {
|
||
|
return dayjs(v).format('YYYY-MM-DD HH:mm')
|
||
|
},
|
||
|
)
|
||
|
}
|
||
2 years ago
|
|
||
|
export function validateDateFormat(v: string) {
|
||
2 years ago
|
return dateFormats.includes(v)
|
||
2 years ago
|
}
|
||
|
|
||
|
export function validateDateWithUnknownFormat(v: string) {
|
||
|
let res = 0
|
||
2 years ago
|
for (const format of dateFormats) {
|
||
2 years ago
|
res |= dayjs(v, format, true).isValid() as any
|
||
|
}
|
||
|
return res
|
||
|
}
|