feat: enhance cancellation parser to support mixed wording and add tests for hospital cancellations
This commit is contained in:
@@ -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]}`);
|
||||
|
||||
Reference in New Issue
Block a user