feat: enhance cancellation parser to support mixed wording and add tests for hospital cancellations

This commit is contained in:
2026-10-05 11:17:19 +03:00
parent 666a0b268f
commit e511f74aea
5 changed files with 67 additions and 4 deletions

View File

@@ -46,8 +46,8 @@ function parseDate(text, publishedAt) {
const [full, d, m] = args;
const y = i === 1 ? undefined : args[3];
const offset = args.at(-2);
// In carrier posts “с остановки ... на 09.10” is a departure, not a date.
if (i === 1 && /с\s+остановк[иа]\s+[^\n]*$/i.test(dateText.slice(0, offset))) return full;
// “С/от остановки ... на 09.10” describes a departure, not a date.
if (i === 1 && /(?:с|от)\s+остановк[иа]\s+[^\n]*$/i.test(dateText.slice(0, offset))) return full;
dates.push(inferYear(d, i === 2 ? MONTHS.indexOf(m.toLowerCase()) + 1 : m, y, publicationDate));
return ' ';
});
@@ -95,7 +95,7 @@ function parseCancellation({ text = '', publishedAt, hasMedia = false }, { prese
const groups = [];
for (const [i, route] of routeMatches.entries()) {
const section = parsedDate.dateText.slice(route.index + route[0].length, routeMatches[i + 1]?.index);
const stopPattern = /с\s+остановк[иа]\s+(.+?)\s+(?:на|в)\s+((?:\d{1,2}[:.]\d{2}(?:\s*[,;]\s*|\s+и\s+|\s+(?=\d))?)+)/giu;
const stopPattern = /(?:с|от)\s+остановк[иа]\s+(.+?)\s+(?:на|в)\s+((?:\d{1,2}[:.]\d{2}(?:\s*[,;]\s*|\s+и\s+|\s+(?=\d))?)+)/giu;
const departures = [];
for (const stop of section.matchAll(stopPattern)) {
const times = [...stop[2].matchAll(TIME)].map(t => `${t[1].padStart(2, '0')}:${t[2]}`);