// start: min(now - retention, cluster create time)
// end: now - 1min
export function getPitrTimeRange(clusterCreateTime: string, hours: number) {
  if (!clusterCreateTime || !hours) {
    return [undefined, undefined]
  }

  const createTime = new Date(Math.ceil(new Date(clusterCreateTime).getTime() / 1000) * 1000)

  const now = new Date()
  now.setMilliseconds(0)

  const retentionStart = new Date(now.getTime() - hours * 60 * 60 * 1000)

  const startTime = new Date(Math.max(createTime.getTime(), retentionStart.getTime()))

  const endTime = new Date(Math.ceil(now.getTime() - 60 * 1000))
  endTime.setMilliseconds(0)

  return [startTime, endTime]
}
