Skip to content

Commit

Permalink
parser: add more tolerance for errors in date format
Browse files Browse the repository at this point in the history
  • Loading branch information
SantriptaSharma committed Oct 26, 2023
1 parent d5615af commit 813c4a2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/utils/parse-dining.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ async function ParseXlsx(path: string, year: number): Promise<MessMenu[]>
Dinner: menu.getRows(38, 11).map(row => row.values) as xl.CellValue[][]
}

const firstDate = menu.getCell(2, 2).value as string;
const startString = firstDate.trim().replace(/(\d)((rd)|(st)|(th)|(nd))/g, "$1") + ` ${year}`;
const startTimestamp = Date.parse(startString);
let firstDate = menu.getCell(2, 2).value as string;
firstDate = firstDate.trim().replace(/(\d)((rd)|(st)|(th)|(nd))/g, "$1");
firstDate = /(\d{1,2})-?([A-Za-z]+)/.exec(firstDate).slice(1, 3).join("-") + ` ${year}`;
console.log(firstDate);
const startTimestamp = Date.parse(firstDate);
if (Number.isNaN(startTimestamp))
{
throw new Error("Invalid date");
Expand Down

0 comments on commit 813c4a2

Please sign in to comment.