From 59b5d16818fd599766b6c6eb2cd9d536d020d415 Mon Sep 17 00:00:00 2001 From: Johannes Nussbaum <39048939+jnussbaum@users.noreply.github.com> Date: Fri, 5 Jan 2024 10:27:12 +0100 Subject: [PATCH] feat(excel2xml): find_date_in_string(): allow time spans of 1 day (DEV-3154) (#720) --- src/dsp_tools/commands/excel2xml/excel2xml_lib.py | 2 +- test/unittests/commands/excel2xml/test_excel2xml_lib.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/dsp_tools/commands/excel2xml/excel2xml_lib.py b/src/dsp_tools/commands/excel2xml/excel2xml_lib.py index 7739d8186..8a8eb7ed5 100644 --- a/src/dsp_tools/commands/excel2xml/excel2xml_lib.py +++ b/src/dsp_tools/commands/excel2xml/excel2xml_lib.py @@ -266,7 +266,7 @@ def _from_eur_date_range(eur_date_range: Match[str]) -> str: endyear = _expand_2_digit_year(endyear) startdate = datetime.date(startyear, startmonth, startday) enddate = datetime.date(endyear, endmonth, endday) - if enddate <= startdate: + if enddate < startdate: raise ValueError return f"GREGORIAN:CE:{startdate.isoformat()}:CE:{enddate.isoformat()}" diff --git a/test/unittests/commands/excel2xml/test_excel2xml_lib.py b/test/unittests/commands/excel2xml/test_excel2xml_lib.py index 166a58699..e4e9982ea 100644 --- a/test/unittests/commands/excel2xml/test_excel2xml_lib.py +++ b/test/unittests/commands/excel2xml/test_excel2xml_lib.py @@ -216,8 +216,8 @@ def test_find_date_in_string_eur_date_range(self) -> None: """template: 27.-28.1.1900""" assert excel2xml.find_date_in_string("x 25.-26.2.0800 x") == "GREGORIAN:CE:0800-02-25:CE:0800-02-26" assert excel2xml.find_date_in_string("x 25. - 26.2.0800 x") == "GREGORIAN:CE:0800-02-25:CE:0800-02-26" + assert excel2xml.find_date_in_string("x 25.-25.2.0800 x") == "GREGORIAN:CE:0800-02-25:CE:0800-02-25" assert excel2xml.find_date_in_string("x 25.-24.2.0800 x") is None - assert excel2xml.find_date_in_string("x 25.-25.2.0800 x") is None def test_find_date_in_string_eur_date_range_2_digit(self) -> None: cur = str(datetime.date.today().year - 2000) # in 2024, this will be "24" @@ -229,10 +229,9 @@ def test_find_date_in_string_eur_date_range_across_month(self) -> None: """template: 26.2.-24.3.1948""" assert excel2xml.find_date_in_string("x _1.3. - 25.4.2022_ x") == "GREGORIAN:CE:2022-03-01:CE:2022-04-25" assert excel2xml.find_date_in_string("x (01.03. - 25.04.2022) x") == "GREGORIAN:CE:2022-03-01:CE:2022-04-25" - assert excel2xml.find_date_in_string("x 28.2.-1.12.1515 x") == "GREGORIAN:CE:1515-02-28:CE:1515-12-01" + assert excel2xml.find_date_in_string("x 28.2.-28.2.1515 x") == "GREGORIAN:CE:1515-02-28:CE:1515-02-28" assert excel2xml.find_date_in_string("x 28.2.-26.2.1515 x") is None - assert excel2xml.find_date_in_string("x 28.2.-28.2.1515 x") is None def test_find_date_in_string_eur_date_range_across_month_2_digit(self) -> None: cur = str(datetime.date.today().year - 2000) # in 2024, this will be "24" @@ -246,10 +245,10 @@ def test_find_date_in_string_eur_date_range_across_year(self) -> None: assert excel2xml.find_date_in_string("x 25.12.2022 - 3.1.2024 x") == "GREGORIAN:CE:2022-12-25:CE:2024-01-03" assert excel2xml.find_date_in_string("x 25/12/2022-03/01/2024 x") == "GREGORIAN:CE:2022-12-25:CE:2024-01-03" assert excel2xml.find_date_in_string("x 25/12/2022 - 3/1/2024 x") == "GREGORIAN:CE:2022-12-25:CE:2024-01-03" + assert excel2xml.find_date_in_string("x 25.12.2022-25.12.2022 x") == "GREGORIAN:CE:2022-12-25:CE:2022-12-25" + assert excel2xml.find_date_in_string("x 25/12/2022-25/12/2022 x") == "GREGORIAN:CE:2022-12-25:CE:2022-12-25" assert excel2xml.find_date_in_string("x 25.12.2022-03.01.2022 x") is None - assert excel2xml.find_date_in_string("x 25.12.2022-25.12.2022 x") is None assert excel2xml.find_date_in_string("x 25/12/2022-03/01/2022 x") is None - assert excel2xml.find_date_in_string("x 25/12/2022-25/12/2022 x") is None def test_find_date_in_string_eur_date_range_across_year_2_digit(self) -> None: cur = str(datetime.date.today().year - 2000) # in 2024, this will be "24"