diff --git a/scripts/resume_sync.py b/scripts/resume_sync.py index a6dfa38..d669ea9 100644 --- a/scripts/resume_sync.py +++ b/scripts/resume_sync.py @@ -122,9 +122,15 @@ def profile_to_library(payload: dict[str, Any]) -> tuple[str, dict[str, Any]]: period = (exp.get("period") or "").strip() location = (exp.get("location") or "").strip() - # Split period back to start_date / end_date - sep_period = period.replace("\u2013", "-").replace("\u2014", "-") - date_parts = [p.strip() for p in sep_period.split("-", 1)] + # Split period back to start_date / end_date. + # Split on the dash/dash separator BEFORE normalising to plain hyphens + # so that ISO dates like "2023-01 – 2025-03" round-trip correctly. + if "\u2013" in period: # en-dash + date_parts = [p.strip() for p in period.split("\u2013", 1)] + elif "\u2014" in period: # em-dash + date_parts = [p.strip() for p in period.split("\u2014", 1)] + else: + date_parts = [period.strip()] if period.strip() else [] start_date = date_parts[0] if date_parts else "" end_date = date_parts[1] if len(date_parts) > 1 else "" diff --git a/tests/test_resume_sync.py b/tests/test_resume_sync.py index a35b1ba..fa41a67 100644 --- a/tests/test_resume_sync.py +++ b/tests/test_resume_sync.py @@ -139,6 +139,32 @@ def test_profile_to_library_period_split(): assert struct["experience"][0]["start_date"] == "2023" assert struct["experience"][0]["end_date"] == "present" +def test_profile_to_library_period_split_iso_dates(): + """ISO dates (with hyphens) must round-trip through the period field correctly.""" + payload = { + **PROFILE_PAYLOAD, + "experience": [{ + **PROFILE_PAYLOAD["experience"][0], + "period": "2023-01 \u2013 2025-03", + }], + } + _, struct = profile_to_library(payload) + assert struct["experience"][0]["start_date"] == "2023-01" + assert struct["experience"][0]["end_date"] == "2025-03" + +def test_profile_to_library_period_split_em_dash(): + """Em-dash separator is also handled.""" + payload = { + **PROFILE_PAYLOAD, + "experience": [{ + **PROFILE_PAYLOAD["experience"][0], + "period": "2022-06 \u2014 2023-12", + }], + } + _, struct = profile_to_library(payload) + assert struct["experience"][0]["start_date"] == "2022-06" + assert struct["experience"][0]["end_date"] == "2023-12" + def test_profile_to_library_education_round_trip(): _, struct = profile_to_library(PROFILE_PAYLOAD) assert struct["education"][0]["institution"] == "State University"