import { format, getTime, formatDistanceToNow } from 'date-fns';

// ----------------------------------------------------------------------

export function fDate(date: Date | string | number) {
  return format(new Date(date), 'dd MMM yyyy');
}

export function fDateTime(date: Date | string | number) {
  return format(new Date(date), 'dd MMM yyyy p');
}

export function fDateTimesecond(date: Date | string | number) {
  return format(new Date(date), 'dd MMM yyyy HH:mm:ss');
}

export function fTimestamp(date: Date | string | number) {
  return getTime(new Date(date));
}

export function fDateTimeSuffix(date: Date | string | number) {
  return format(new Date(date), 'dd/MM/yyyy hh:mm p');
}

export function fToNow(date: Date | string | number) {
  return formatDistanceToNow(new Date(date), {
    addSuffix: true,
  });
}

export function fPostFormat(date: Date | string | number) {
  return format(new Date(date), 'yyyy-MM-dd HH:mm:ss');
}

export function fDateOnly(date: Date | string | number) {
  return format(new Date(date), 'yyyy-MM-dd');
}

export function toTitleCase(str: string | null) {
  return str.replace(/\w\S*/g, function(txt) {
      return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  });
}
