import { dayjs } from './dayjs';

export const formatDate = (v: string | null | undefined): string =>
  v ? dayjs(v).format('YYYY-MM-DD') : '--';

export const formatDateTime = (v: string | null | undefined): string =>
  v ? dayjs(v).format('YYYY-MM-DD HH:mm') : '--';

export const formatRelative = (v: string | null | undefined): string =>
  v ? dayjs(v).fromNow() : '--';

export const calcAge = (birthDate: string | null | undefined): string => {
  if (!birthDate) return '--';
  const age = dayjs().diff(dayjs(birthDate), 'year');
  return age >= 0 ? `${age}岁` : '--';
};
