fix minor issues and add more tests

This commit is contained in:
Sina Atalay
2024-11-17 18:35:02 -05:00
committed by Sina Atalay
parent 2f22d8c7e8
commit 9c2e5caac5
2 changed files with 22 additions and 4 deletions

View File

@@ -195,11 +195,11 @@ def compute_time_span_string(
# Calculate the number of years and months between start_date and end_date:
how_many_years = timespan_in_days // 365
how_many_months = round((timespan_in_days % 365) / 30)
how_many_months = (timespan_in_days % 365) // 30 + 1
# Deal with overflow (prevent rounding to 1 year 12 months, etc.)
how_many_years += how_many_months // 12
how_many_months %= 12
# Format the number of years and months between start_date and end_date:
if how_many_years == 0:
how_many_years_string = None
@@ -209,7 +209,9 @@ def compute_time_span_string(
how_many_years_string = f"{how_many_years} {LOCALE_CATALOG['years']}"
# Format the number of months between start_date and end_date:
if how_many_months == 1 or (how_many_years_string is None and how_many_months == 0):
if how_many_months == 1 or (
how_many_years_string is None and how_many_months == 0
):
how_many_months_string = f"1 {LOCALE_CATALOG['month']}"
elif how_many_months == 0:
how_many_months_string = None

View File

@@ -184,6 +184,22 @@ def test_if_the_schema_is_the_latest(root_directory_path):
"2020 2021",
"1 year 1 month",
),
(
"2020-01-01",
"2022-01-01",
None,
"Jan 2020 Jan 2022",
"2020 2022",
"2 years 1 month",
),
(
"2020-01-01",
"2021-12-10",
None,
"Jan 2020 Dec 2021",
"2020 2021",
"2 years",
),
(
Date(2020, 1, 1),
Date(2021, 1, 1),
@@ -230,7 +246,7 @@ def test_if_the_schema_is_the_latest(root_directory_path):
None,
"Feb 2020 present",
"2020 present",
"3 years 11 months",
"4 years",
),
("2020-01-01", "2021-01-01", "2023-02-01", "Feb 2023", "2023", ""),
("2020", "2021", None, "2020 2021", "2020 2021", "1 year"),