Download app/services/dates.py from nvikou/Sheetly: direct link, hf CLI and curl.
- Browser
- Download file 793 Bytes
-
https://huggingface.co/spaces/nvikou/Sheetly/resolve/main/app/services/dates.py
- Command line
-
hf download hf://spaces/nvikou/Sheetly/app/services/dates.py
-
curl -L -o dates.py https://huggingface.co/spaces/nvikou/Sheetly/resolve/main/app/services/dates.py
793 Bytes
| """Date parsing helpers.""" | |
| from __future__ import annotations | |
| from datetime import datetime | |
| from typing import Any | |
| _DATE_FORMATS = ("%Y-%m-%d", "%d/%m/%Y", "%d.%m.%Y") | |
| def parse_date(value: Any) -> datetime | None: | |
| """Parse common ISO / EU date strings.""" | |
| if not value or not isinstance(value, str): | |
| return None | |
| raw = value.strip()[:10] | |
| for fmt in _DATE_FORMATS: | |
| try: | |
| return datetime.strptime(raw, fmt) | |
| except ValueError: | |
| continue | |
| return None | |
| def to_iso_date(value: str | None) -> str | None: | |
| """Normalize a date string to YYYY-MM-DD when possible.""" | |
| if not value: | |
| return None | |
| parsed = parse_date(value) | |
| if parsed is None: | |
| return value.strip() | |
| return parsed.strftime("%Y-%m-%d") | |