ant-design-vue/components/date-picker/utils.ts

17 lines
432 B
TypeScript
Raw Normal View History

2021-06-26 01:35:40 +00:00
import type moment from 'moment';
2020-11-03 14:57:14 +00:00
2020-10-14 15:12:51 +00:00
type Value = moment.Moment | undefined | null;
type Format = string | string[] | undefined | ((val?: Value) => string | string[] | undefined);
export function formatDate(value: Value, format: Format) {
if (!value) {
return '';
}
if (Array.isArray(format)) {
format = format[0];
}
if (typeof format === 'function') {
return format(value);
}
return value.format(format);
}