/**
 * 将秒钟转为描述
 */
export function toDescriptionFromSecond(data) {
  let seconds = data;
  if (data instanceof String) {
    seconds = parseInt(data)
  }
  let positive = true;
  if (seconds < 0) {
    positive =false;
    seconds = -seconds;
  }

  let desc = {
    day: parseInt(seconds / 86400),
    hour: parseInt((seconds % 86400) / 3600),
    minute: parseInt((seconds % 3600) / 60),
    second: parseInt(seconds % 60),
    positive: positive,
  }

  desc.text = `${positive ? '' : '-'} `;
  if (desc.day > 0) {
    desc.text += desc.day + ' 天 ';
  }
  if (desc.day > 0 || desc.hour > 0) {
    desc.text += desc.hour + ' 时 ';
  }
  if (desc.day > 0 || desc.hour > 0 || desc.minute > 0) {
    desc.text += desc.minute + ' 分 ';
  }
  desc.text += desc.second + ' 秒';
  return desc;
}

// 增加日期
export function plusDays(date, day) {
  let result = new Date();
  if (date instanceof Date) {
    result = new Date(date.getTime());
  } else if (date instanceof String) {
    result = new Date(date);
  }
  return result.setDate(result.getDate() + day);
}
