Skip to content

Commit

Permalink
fix minor issues and add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaatalay committed Nov 17, 2024
1 parent 2f22d8c commit 9c2e5ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 5 additions & 3 deletions rendercv/data/models/computers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 17 additions & 1 deletion tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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"),
Expand Down

0 comments on commit 9c2e5ca

Please sign in to comment.