This commit is contained in:
zyp
2026-11-25 20:46:42 +08:00
parent 066a5023b7
commit 1ae94dfb1f
17 changed files with 633 additions and 55 deletions
+23
View File
@@ -5,6 +5,29 @@ import re
from calendar import monthrange
_DAY = r"(\d{4})[-/年](\d{1,2})[-/月](\d{1,2})日?"
_CLOSED_DATES = re.compile(rf"(?<!\d){_DAY}(?:\s*(?:至|到|[~~—–])\s*{_DAY})?(?!\d)")
def explicit_date_bounds(text: str) -> tuple[str, str] | None:
"""Parse a complete date or a closed range, including Chinese date notation."""
match = _CLOSED_DATES.fullmatch(text.strip())
if not match:
return None
digits = match.groups()
try:
first = date(*map(int, digits[:3]))
last = date(*map(int, digits[3:])) if digits[3] else first
except ValueError:
return None
return (first.isoformat(), last.isoformat()) if first <= last else None
def single_explicit_date_span(text: str) -> str:
spans = list(_CLOSED_DATES.finditer(text))
return spans[0].group() if len(spans) == 1 else ""
def explicit_relative_period(message: str):
"""Canonical whole periods only; mixed ranges and specific weekdays stay explicit.