data_models: don't use dots after month abbrevations and use dash instead of "to" in date ranges

This commit is contained in:
Sina Atalay 2024-06-06 17:22:41 +03:00
parent a0460d3ddd
commit 9deb39246d
2 changed files with 57 additions and 71 deletions

View File

@ -38,29 +38,9 @@ from .themes.engineeringresumes import EngineeringresumesThemeOptions
# Disable Pydantic warnings: # Disable Pydantic warnings:
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
locale_catalog = {
"month": "month", # The dictionary below will be overwritten by LocaleCatalog class.
"months": "months", locale_catalog = {}
"year": "year",
"years": "years",
"present": "present",
"to": "to",
# Month abbreviations are taken from https://web.library.yale.edu/cataloging/months:
"abbreviations_for_months": [
"Jan.",
"Feb.",
"Mar.",
"Apr.",
"May",
"June",
"July",
"Aug.",
"Sept.",
"Oct.",
"Nov.",
"Dec.",
],
}
def get_date_object(date: str | int) -> Date: def get_date_object(date: str | int) -> Date:
@ -1102,27 +1082,32 @@ class LocaleCatalog(RenderCVBaseModel):
validate_default=True, # To initialize the locale catalog with the default values validate_default=True, # To initialize the locale catalog with the default values
) )
to: Optional[str] = pydantic.Field( to: Optional[str] = pydantic.Field(
default="to", default="--",
title='Translation of "To"', title='Translation of "To"',
description='Translation of the word "to" in the locale.', description=(
"The word or character used to indicate a range in the locale (e.g.,"
' "2020 - 2021").'
),
validate_default=True, # To initialize the locale catalog with the default values validate_default=True, # To initialize the locale catalog with the default values
) )
abbreviations_for_months: Optional[ abbreviations_for_months: Optional[
Annotated[list[str], at.Len(min_length=12, max_length=12)] Annotated[list[str], at.Len(min_length=12, max_length=12)]
] = pydantic.Field( ] = pydantic.Field(
# Month abbreviations are taken from
# https://web.library.yale.edu/cataloging/months:
default=[ default=[
"Jan.", "Jan",
"Feb.", "Feb",
"Mar.", "Mar",
"Apr.", "Apr",
"May", "May",
"June", "June",
"July", "July",
"Aug.", "Aug",
"Sept.", "Sept",
"Oct.", "Oct",
"Nov.", "Nov",
"Dec.", "Dec",
], ],
title="Abbreviations of Months", title="Abbreviations of Months",
description="Abbreviations of the months in the locale.", description="Abbreviations of the months in the locale.",
@ -1140,6 +1125,7 @@ class LocaleCatalog(RenderCVBaseModel):
return value return value
LocaleCatalog() # Initialize the locale catalog with the default values
# ====================================================================================== # ======================================================================================
# ====================================================================================== # ======================================================================================

View File

@ -42,18 +42,18 @@ def test_get_date_object(date, expected_date_object, expected_error):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"date, expected_date_string", "date, expected_date_string",
[ [
(Date(2020, 1, 1), "Jan. 2020"), (Date(2020, 1, 1), "Jan 2020"),
(Date(2020, 2, 1), "Feb. 2020"), (Date(2020, 2, 1), "Feb 2020"),
(Date(2020, 3, 1), "Mar. 2020"), (Date(2020, 3, 1), "Mar 2020"),
(Date(2020, 4, 1), "Apr. 2020"), (Date(2020, 4, 1), "Apr 2020"),
(Date(2020, 5, 1), "May 2020"), (Date(2020, 5, 1), "May 2020"),
(Date(2020, 6, 1), "June 2020"), (Date(2020, 6, 1), "June 2020"),
(Date(2020, 7, 1), "July 2020"), (Date(2020, 7, 1), "July 2020"),
(Date(2020, 8, 1), "Aug. 2020"), (Date(2020, 8, 1), "Aug 2020"),
(Date(2020, 9, 1), "Sept. 2020"), (Date(2020, 9, 1), "Sept 2020"),
(Date(2020, 10, 1), "Oct. 2020"), (Date(2020, 10, 1), "Oct 2020"),
(Date(2020, 11, 1), "Nov. 2020"), (Date(2020, 11, 1), "Nov 2020"),
(Date(2020, 12, 1), "Dec. 2020"), (Date(2020, 12, 1), "Dec 2020"),
], ],
) )
def test_format_date(date, expected_date_string): def test_format_date(date, expected_date_string):
@ -225,71 +225,71 @@ def test_generate_json_schema_file(tmp_path):
"2020-01-01", "2020-01-01",
"2021-01-01", "2021-01-01",
None, None,
"Jan. 2020 to Jan. 2021", "Jan 2020 -- Jan 2021",
"2020 to 2021", "2020 -- 2021",
"1 year 1 month", "1 year 1 month",
), ),
( (
Date(2020, 1, 1), Date(2020, 1, 1),
Date(2021, 1, 1), Date(2021, 1, 1),
None, None,
"Jan. 2020 to Jan. 2021", "Jan 2020 -- Jan 2021",
"2020 to 2021", "2020 -- 2021",
"1 year 1 month", "1 year 1 month",
), ),
( (
"2020-01", "2020-01",
"2021-01", "2021-01",
None, None,
"Jan. 2020 to Jan. 2021", "Jan 2020 -- Jan 2021",
"2020 to 2021", "2020 -- 2021",
"1 year 1 month", "1 year 1 month",
), ),
( (
"2020-01", "2020-01",
"2021-01-01", "2021-01-01",
None, None,
"Jan. 2020 to Jan. 2021", "Jan 2020 -- Jan 2021",
"2020 to 2021", "2020 -- 2021",
"1 year 1 month", "1 year 1 month",
), ),
( (
"2020-01-01", "2020-01-01",
"2021-01", "2021-01",
None, None,
"Jan. 2020 to Jan. 2021", "Jan 2020 -- Jan 2021",
"2020 to 2021", "2020 -- 2021",
"1 year 1 month", "1 year 1 month",
), ),
( (
"2020-01-01", "2020-01-01",
None, None,
None, None,
"Jan. 2020 to present", "Jan 2020 -- present",
"2020 to present", "2020 -- present",
"4 years 1 month", "4 years 1 month",
), ),
( (
"2020-02-01", "2020-02-01",
"present", "present",
None, None,
"Feb. 2020 to present", "Feb 2020 -- present",
"2020 to present", "2020 -- present",
"3 years 11 months", "3 years 11 months",
), ),
("2020-01-01", "2021-01-01", "2023-02-01", "Feb. 2023", "2023", ""), ("2020-01-01", "2021-01-01", "2023-02-01", "Feb 2023", "2023", ""),
("2020", "2021", None, "2020 to 2021", "2020 to 2021", "1 year"), ("2020", "2021", None, "2020 -- 2021", "2020 -- 2021", "1 year"),
("2020", None, None, "2020 to present", "2020 to present", "4 years"), ("2020", None, None, "2020 -- present", "2020 -- present", "4 years"),
("2020-10-10", "2022", None, "Oct. 2020 to 2022", "2020 to 2022", "2 years"), ("2020-10-10", "2022", None, "Oct 2020 -- 2022", "2020 -- 2022", "2 years"),
( (
"2020-10-10", "2020-10-10",
"2020-11-05", "2020-11-05",
None, None,
"Oct. 2020 to Nov. 2020", "Oct 2020 -- Nov 2020",
"2020 to 2020", "2020 -- 2020",
"1 month", "1 month",
), ),
("2022", "2023-10-10", None, "2022 to Oct. 2023", "2022 to 2023", "1 year"), ("2022", "2023-10-10", None, "2022 -- Oct 2023", "2022 -- 2023", "1 year"),
( (
"2020-01-01", "2020-01-01",
"present", "present",
@ -322,12 +322,12 @@ def test_generate_json_schema_file(tmp_path):
"My Custom Date", "My Custom Date",
"", "",
), ),
(None, None, "2020-01-01", "Jan. 2020", "2020", ""), (None, None, "2020-01-01", "Jan 2020", "2020", ""),
(None, None, "2020-09", "Sept. 2020", "2020", ""), (None, None, "2020-09", "Sept 2020", "2020", ""),
(None, None, Date(2020, 1, 1), "Jan. 2020", "2020", ""), (None, None, Date(2020, 1, 1), "Jan 2020", "2020", ""),
(None, None, None, "", "", ""), (None, None, None, "", "", ""),
(None, "2020-01-01", None, "Jan. 2020", "2020", ""), (None, "2020-01-01", None, "Jan 2020", "2020", ""),
(None, "present", None, "Jan. 2024", "2024", ""), (None, "present", None, "Jan 2024", "2024", ""),
("2002", "2020", "2024", "2024", "2024", ""), ("2002", "2020", "2024", "2024", "2024", ""),
], ],
) )
@ -350,8 +350,8 @@ def test_dates(
@pytest.mark.parametrize( @pytest.mark.parametrize(
"date, expected_date_string", "date, expected_date_string",
[ [
("2020-01-01", "Jan. 2020"), ("2020-01-01", "Jan 2020"),
("2020-01", "Jan. 2020"), ("2020-01", "Jan 2020"),
("2020", "2020"), ("2020", "2020"),
], ],
) )