import { RUMObject } from '../../types'

export const isRumObjectsLinkedToYear = (rumObjects: RUMObject[], year: number) => {
  // Check the year is a valid year
  if (year.toString().length !== 4) {
    return false
  }

  const exitDates = rumObjects
    .map((rumObject) => rumObject.exitDate)
    .filter((exitDate) => exitDate !== undefined)
    .sort()
  return exitDates.length > 0 && exitDates.some((exitDate) => isDateLinkedToYear(exitDate, year))
}

export const isDateLinkedToYear = (date: string, year: number) => {
  return date.endsWith(year.toString())
}
