enhanced deadline parsing
This commit is contained in:
@@ -1678,12 +1678,35 @@ function extractDeadlineFromPostText(postElement) {
|
|||||||
|
|
||||||
// German date patterns
|
// German date patterns
|
||||||
const patterns = [
|
const patterns = [
|
||||||
// DD.MM.YYYY or DD.MM.YY
|
// DD.MM.YYYY or DD.MM.YY (with optional time like ", 23:59Uhr")
|
||||||
/\b(\d{1,2})\.(\d{1,2})\.(\d{2,4})\b/g,
|
/\b(\d{1,2})\.(\d{1,2})\.(\d{2,4})(?!\d)/g,
|
||||||
// DD.MM (without year)
|
// DD.MM (without year, optional trailing time)
|
||||||
/\b(\d{1,2})\.(\d{1,2})\.\s*(?!\d)/g
|
/\b(\d{1,2})\.(\d{1,2})\.(?!\d)/g
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const extractTimeAfterIndex = (text, index) => {
|
||||||
|
const tail = text.slice(index, index + 40);
|
||||||
|
const timeMatch = /^\s*(?:[,;:-]|\b)?\s*(?:um|ab|bis)?\s*(?:ca\.?)?\s*(\d{1,2})[:.](\d{2})\s*(?:uhr|h)?/i.exec(tail);
|
||||||
|
if (!timeMatch) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const hour = parseInt(timeMatch[1], 10);
|
||||||
|
const minute = parseInt(timeMatch[2], 10);
|
||||||
|
if (Number.isNaN(hour) || Number.isNaN(minute)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return { hour, minute };
|
||||||
|
};
|
||||||
|
|
||||||
|
const hasInclusiveKeywordNear = (text, index) => {
|
||||||
|
const windowStart = Math.max(0, index - 40);
|
||||||
|
const windowText = text.slice(windowStart, index).toLowerCase();
|
||||||
|
return /\b(einschlie(?:ß|ss)lich|inklusive|inkl\.)\b/.test(windowText);
|
||||||
|
};
|
||||||
|
|
||||||
const foundDates = [];
|
const foundDates = [];
|
||||||
|
|
||||||
for (const pattern of patterns) {
|
for (const pattern of patterns) {
|
||||||
@@ -1692,6 +1715,7 @@ function extractDeadlineFromPostText(postElement) {
|
|||||||
const day = parseInt(match[1], 10);
|
const day = parseInt(match[1], 10);
|
||||||
const month = parseInt(match[2], 10);
|
const month = parseInt(match[2], 10);
|
||||||
let year = match[3] ? parseInt(match[3], 10) : today.getFullYear();
|
let year = match[3] ? parseInt(match[3], 10) : today.getFullYear();
|
||||||
|
const matchIndex = match.index;
|
||||||
|
|
||||||
// Handle 2-digit years
|
// Handle 2-digit years
|
||||||
if (year < 100) {
|
if (year < 100) {
|
||||||
@@ -1704,6 +1728,13 @@ function extractDeadlineFromPostText(postElement) {
|
|||||||
|
|
||||||
// Check if date is valid (e.g., not 31.02.)
|
// Check if date is valid (e.g., not 31.02.)
|
||||||
if (date.getMonth() === month - 1 && date.getDate() === day) {
|
if (date.getMonth() === month - 1 && date.getDate() === day) {
|
||||||
|
const timeInfo = extractTimeAfterIndex(fullText, pattern.lastIndex);
|
||||||
|
if (timeInfo) {
|
||||||
|
date.setHours(timeInfo.hour, timeInfo.minute, 0, 0);
|
||||||
|
} else if (hasInclusiveKeywordNear(fullText, matchIndex)) {
|
||||||
|
date.setHours(23, 59, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// Only add if date is in the future
|
// Only add if date is in the future
|
||||||
if (date > today) {
|
if (date > today) {
|
||||||
foundDates.push(date);
|
foundDates.push(date);
|
||||||
@@ -1721,12 +1752,20 @@ function extractDeadlineFromPostText(postElement) {
|
|||||||
const monthStr = monthMatch[2].toLowerCase();
|
const monthStr = monthMatch[2].toLowerCase();
|
||||||
const month = monthNames[monthStr];
|
const month = monthNames[monthStr];
|
||||||
const year = today.getFullYear();
|
const year = today.getFullYear();
|
||||||
|
const matchIndex = monthMatch.index;
|
||||||
|
|
||||||
if (month && day >= 1 && day <= 31) {
|
if (month && day >= 1 && day <= 31) {
|
||||||
const date = new Date(year, month - 1, day, 0, 0, 0, 0);
|
const date = new Date(year, month - 1, day, 0, 0, 0, 0);
|
||||||
|
|
||||||
// Check if date is valid
|
// Check if date is valid
|
||||||
if (date.getMonth() === month - 1 && date.getDate() === day) {
|
if (date.getMonth() === month - 1 && date.getDate() === day) {
|
||||||
|
const timeInfo = extractTimeAfterIndex(fullText, monthPattern.lastIndex);
|
||||||
|
if (timeInfo) {
|
||||||
|
date.setHours(timeInfo.hour, timeInfo.minute, 0, 0);
|
||||||
|
} else if (hasInclusiveKeywordNear(fullText, matchIndex)) {
|
||||||
|
date.setHours(23, 59, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// If date has passed this year, assume next year
|
// If date has passed this year, assume next year
|
||||||
if (date <= today) {
|
if (date <= today) {
|
||||||
date.setFullYear(year + 1);
|
date.setFullYear(year + 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user