|
|
@ -1,4 +1,6 @@ |
|
|
|
import dayjs from 'dayjs' |
|
|
|
import dayjs from 'dayjs' |
|
|
|
|
|
|
|
import customParseFormat from 'dayjs/plugin/customParseFormat' |
|
|
|
|
|
|
|
dayjs.extend(customParseFormat) |
|
|
|
|
|
|
|
|
|
|
|
export const timeAgo = (date: any) => { |
|
|
|
export const timeAgo = (date: any) => { |
|
|
|
return dayjs.utc(date).fromNow() |
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|