// 获取时间戳(秒)
export const getTimestamp = (date) => Math.floor(new Date(date).getTime() / 1000)

// 获取今天与 90 天之前的时间戳(秒)
export const getTimestampsBy90day = () => {
  const today = new Date()
  const ninetyDaysAgo = new Date(today)
  ninetyDaysAgo.setDate(today.getDate() - 90)
  return {
    today: getTimestamp(today),
    ninetyDaysAgo: getTimestamp(ninetyDaysAgo)
  }
}

// 获取今天以及 90 天之前的日期,以 2024-06-01 的格式返回
export const getDatesFormattedBy90day = () => {
  // 获取今天的日期
  const today = new Date()
  // 获取90天前的日期
  const ninetyDaysAgo = new Date(today)
  ninetyDaysAgo.setDate(today.getDate() - 90)

  // 格式化日期函数
  function formatDate(date) {
    const year = date.getFullYear()
    const month = String(date.getMonth() + 1).padStart(2, '0')
    const day = String(date.getDate()).padStart(2, '0')
    return `${year}-${month}-${day}`
  }
  // 返回格式化后的日期
  return {
    today: formatDate(today),
    ninetyDaysAgo: formatDate(ninetyDaysAgo)
  }
}
