/**
 * 计算周年
 */
export function calcFullYear(date) {
  if (date == null ) {
    return 0;
  }
  let start = toDate(date);
  let end = new Date();

  return Math.floor((end.getTime() - start.getTime()) / 31536000000)
}

/**
 * 计算年龄
 */
export function calcBirthDay(birthday) {
  if (birthday === null) {
    return 0;
  }
  let now = new Date();
  let start = toDate(birthday);

  return now.getFullYear() - start.getFullYear() + 1;
}

/**
 * 转为日期
 */
export function toDate(data) {
  let date = data;
  if (typeof date === 'string') {
    date = new Date(data);
  }
  return date;
}

/**
 * 计算两个时间相差多少秒
 */
export function calcSecond(start, end) {
  if (start == null || end == null) {
    return 0;
  }
  let startDate = toDate(start);
  let endDate = toDate(end);
  return Math.floor((endDate.getTime() - startDate.getTime()) / 1000);
}
