async function getSearchDate()

in functions/GPOPackagesFunction/index.js [112:139]


async function getSearchDate(currentPkg) {
  const months = [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December",
  ];

  // parse the month and year from the file name and convert to a Date object
  const fileNameParts = currentPkg.split("_");
  const month = fileNameParts[4];
  const year = fileNameParts[5];
  const pkgDate = new Date(year, months.indexOf(month));
  // add 4 months to the date because the packages are released in the month following
  // a new quarter but the file name includes the last month of the quarter
  pkgDate.setMonth(pkgDate.getMonth() + 4);
  // set the day to the first of the month
  pkgDate.setDate(1);
  return pkgDate;
}