MCPcopy Create free account
hub / github.com/LLMQuant/quant-mind / _parse_crossref_date

Function _parse_crossref_date

quantmind/preprocess/fetch/doi.py:46–62  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

44
45
46def _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
65def _format_authors(items: list[dict[str, str]] | None) -> tuple[str, ...]:

Callers 1

resolve_doiFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected