Convert Crossref's ``date-parts: [[YYYY, MM, DD]]`` to a UTC datetime. Crossref returns date-parts arrays where missing components are simply omitted (``[[2024]]`` for year-only, ``[[2024, 5]]`` for year+month). Default missing month/day to January 1.
(parts: list[list[int]] | None)
| 44 | |
| 45 | |
| 46 | def _parse_crossref_date(parts: list[list[int]] | None) -> datetime | None: |
| 47 | """Convert Crossref's ``date-parts: [[YYYY, MM, DD]]`` to a UTC datetime. |
| 48 | |
| 49 | Crossref returns date-parts arrays where missing components are simply |
| 50 | omitted (``[[2024]]`` for year-only, ``[[2024, 5]]`` for year+month). |
| 51 | Default missing month/day to January 1. |
| 52 | """ |
| 53 | if not parts or not parts[0]: |
| 54 | return None |
| 55 | components = parts[0] |
| 56 | year = components[0] |
| 57 | month = components[1] if len(components) > 1 else 1 |
| 58 | day = components[2] if len(components) > 2 else 1 |
| 59 | try: |
| 60 | return datetime(year, month, day, tzinfo=timezone.utc) |
| 61 | except (ValueError, TypeError): |
| 62 | return None |
| 63 | |
| 64 | |
| 65 | def _format_authors(items: list[dict[str, str]] | None) -> tuple[str, ...]: |