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.
17 lines
427 B
17 lines
427 B
import moment from 'moment';
|
|
|
|
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);
|
|
}
|