f1tness_parser/utils/date_refactor.py

21 lines
761 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
from datetime import date
def parse_training_date(raw_date: str) -> date:
patterns = [
r"^(?P<day>[0-9]{2})\.(?P<month>[0-9]{2})\.(?P<year>[0-9]{4})*",
r"^(?P<year>[0-9]{4})\-(?P<month>[0-9]{2})\-(?P<day>[0-9]{2})*",
r"^(?P<year>[0-9]{4})\.(?P<month>[0-9]{2})\.(?P<day>[0-9]{2})*",
r"^(?P<day>[0-9]{2})\.(?P<month>[0-9]{2})\.(?P<year>[0-9]{4})*",
]
for pattern in patterns:
match = re.match(pattern, raw_date)
if match:
day = int(match.group("day"))
month = int(match.group("month"))
year = int(match.group("year"))
return date(year, month, day)
raise ValueError(f"Не удалось найти дату в строке: {raw_date}")