/*
 * @Author: Gui
 * @Date: 2023-04-07 16:09:33
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-11-16 16:07:25
 * @Description: kxs files
 * @filePath:
 */
const zeroFill = (num: number) => {
  return num < 10 ? `0${num}` : num;
};
export const ListDate = (date: string) => {
  date = date ? date.replace(/-/g, "/") : '';
  if (!date || date === "无") {
    return "暂无时间";
  }
  const timeStamp = new Date(date).getTime();
  const nowTimeStamp = new Date().getTime();
  const timeDifference = Math.floor((nowTimeStamp - timeStamp) / 1000);
  const isThoseYear = new Date(date).getFullYear() === new Date().getFullYear();
  const isThoseMonth = new Date(date).getMonth() === new Date().getMonth();
  const isThoseDay = Math.floor(
    new Date().getDate() - new Date(date).getDate()
  );
  let result = "";
  if (timeDifference < 60 && timeDifference >= 0) {
    result = "刚刚";
  } else if (timeDifference >= 60 && timeDifference < 10 * 60) {
    result = `${Math.floor(timeDifference / 60)}分钟前`;
  } else if (
    timeDifference >= 10 * 60 &&
    isThoseDay === 0 &&
    isThoseMonth &&
    isThoseYear
  ) {
    result = `${zeroFill(new Date(date).getHours())}:${zeroFill(
      new Date(date).getMinutes()
    )}`;
  } else if (
    timeDifference >= 10 * 60 &&
    isThoseDay === 1 &&
    isThoseMonth &&
    isThoseYear
  ) {
    result = `昨天 ${zeroFill(new Date(date).getHours())}:${zeroFill(
      new Date(date).getMinutes()
    )}`;
  } else if (timeDifference >= 10 * 60 && isThoseYear) {
    result = `${zeroFill(new Date(date).getMonth() + 1)}/${zeroFill(
      new Date(date).getDate()
    )} ${zeroFill(new Date(date).getHours())}:${zeroFill(
      new Date(date).getMinutes()
    )}`;
  } else if (
    (timeDifference >= 10 * 60 && !isThoseYear) ||
    timeDifference < 0
  ) {
    result = `${new Date(date).getFullYear()}/${zeroFill(
      new Date(date).getMonth() + 1
    )}/${zeroFill(new Date(date).getDate())} ${zeroFill(
      new Date(date).getHours()
    )}:${zeroFill(new Date(date).getMinutes())}`;
  }
  return result;
};
export const DetailDate = (date: string) => {
  if (!date || date === "无") {
    return "暂无时间";
  }
  const timeStamp = new Date(date).getTime();
  const nowTimeStamp = new Date().getTime();
  const timeDifference = Math.floor((nowTimeStamp - timeStamp) / 1000);
  const isThoseYear = new Date(date).getFullYear() === new Date().getFullYear();
  const isThoseMonth = new Date(date).getMonth() === new Date().getMonth();
  const isThoseDay = Math.floor(
    new Date().getDate() - new Date(date).getDate()
  );
  let result = "";
  if (timeDifference < 60) {
    result = "刚刚";
  } else if (timeDifference >= 60 && timeDifference < 10 * 60) {
    result = `${Math.floor(timeDifference / 60)}分钟前`;
  } else if (
    timeDifference >= 10 * 60 &&
    isThoseDay === 0 &&
    isThoseMonth &&
    isThoseYear
  ) {
    result = `${zeroFill(new Date(date).getHours())}:${zeroFill(
      new Date(date).getMinutes()
    )}`;
  } else if (timeDifference >= 10 * 60 && isThoseDay === 1 && isThoseMonth) {
    result = `昨天 ${zeroFill(new Date(date).getHours())}:${zeroFill(
      new Date(date).getMinutes()
    )}`;
  } else if (timeDifference >= 10 * 60 && isThoseYear) {
    result = `${zeroFill(new Date(date).getMonth() + 1)}月${zeroFill(
      new Date(date).getDate()
    )}日 ${zeroFill(new Date(date).getHours())}:${zeroFill(
      new Date(date).getMinutes()
    )}`;
  } else if (
    (timeDifference >= 10 * 60 && !isThoseYear) ||
    timeDifference < 0
  ) {
    result = `${new Date(date).getFullYear()}年${zeroFill(
      new Date(date).getMonth() + 1
    )}月${zeroFill(new Date(date).getDate())}日 ${zeroFill(
      new Date(date).getHours()
    )}:${zeroFill(new Date(date).getMinutes())}`;
  }
  return result;
};
