Skip to content

Commit

Permalink
feat: Add toggle to display 'Dec. 31st' dates as year-only
Browse files Browse the repository at this point in the history
Closes #65
  • Loading branch information
alexpovel committed Sep 18, 2022
1 parent 1192eef commit 26d46cb
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 9 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ In summary:
- text content like emojis and newlines to control paragraph breaks.

Emojis are user-controlled: if you want them, use them in your `resume.json`; in the future, there might be *templates* with emojis baked in, but you'd have to actively opt into using one.
- date formatting, in a limited fashion through the `dec31_as_year` toggle.
If that toggle is `true`, dates in the format `YYYY-12-31` will be displayed as `YYYY` only.
- lastly, there's a toggle for ASCII-only output.

It only concerns the *template* and controls the drawing of boxes and such (e.g., [`-`](https://unicode-table.com/en/002D/) versus [``](https://unicode-table.com/en/2500/) : only the latter will produce gapless rules).
Expand All @@ -112,7 +114,8 @@ The components may be controlled using the `ancv` field in your `resume.json`:
"template": "Sequential",
"theme": "lollipop",
"ascii_only": false,
"language": "en"
"language": "en",
"dec31_as_year": false
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ancv/data/models/resume.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class TemplateConfig(BaseModel):
theme: Optional[str]
language: Optional[str]
ascii_only: Optional[bool]
dec31_as_year: Optional[bool]


class Meta(BaseModel):
Expand Down
14 changes: 13 additions & 1 deletion ancv/visualization/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ def __init__(
translation: Translation,
locale: Locale,
ascii_only: bool,
dec31_as_year: bool,
) -> None:
self.model = model
self.theme = theme
self.translation = translation
self.locale = locale
self.ascii_only = ascii_only
self.dec31_as_year = dec31_as_year

# This is behavior:
@abstractmethod
Expand Down Expand Up @@ -93,7 +95,13 @@ def render(self) -> str:

@lru_cache(maxsize=1_000)
def format_date(self, date: date) -> str:
return format_date(date, format=self.theme.datefmt.full, locale=self.locale)
format = self.theme.datefmt.full

is_last_doy = date.month == date.max.month and date.day == date.max.day
if is_last_doy and self.dec31_as_year:
format = self.theme.datefmt.year_only

return format_date(date, format=format, locale=self.locale)

@lru_cache(maxsize=1_000)
def format_date_range(
Expand Down Expand Up @@ -153,12 +161,16 @@ def from_model_config(cls, model: ResumeSchema) -> "Template":
if (ascii_only := config.ascii_only) is None:
ascii_only = False

if (dec31_as_year := config.dec31_as_year) is None:
dec31_as_year = False

return template(
model=model,
theme=theme,
translation=translation,
locale=Locale(language),
ascii_only=ascii_only,
dec31_as_year=dec31_as_year,
)

@classmethod
Expand Down
10 changes: 5 additions & 5 deletions ancv/visualization/themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Theme(BaseModel):
sep="•",
range_sep="–",
rulechar="─",
datefmt=DateFormat(full="yyyy-MM", year_only="yyyy-MM"),
datefmt=DateFormat(full="yyyy-MM", year_only="yyyy"),
),
"grayscale": Theme(
emphasis=Emphasis(
Expand All @@ -54,7 +54,7 @@ class Theme(BaseModel):
sep="*",
range_sep="–",
rulechar="─",
datefmt=DateFormat(full="MMMM yyyy", year_only="MMMM yyyy"),
datefmt=DateFormat(full="MMMM yyyy", year_only="yyyy"),
),
"basic": Theme(
emphasis=Emphasis(
Expand All @@ -67,7 +67,7 @@ class Theme(BaseModel):
sep="•",
range_sep="–",
rulechar="─",
datefmt=DateFormat(full="MMMM yyyy", year_only="MMMM yyyy"),
datefmt=DateFormat(full="MMMM yyyy", year_only="yyyy"),
),
"lollipop": Theme(
emphasis=Emphasis(
Expand All @@ -80,7 +80,7 @@ class Theme(BaseModel):
sep="•",
range_sep="➔",
rulechar="─",
datefmt=DateFormat(full="MMMM yyyy", year_only="MMMM yyyy"),
datefmt=DateFormat(full="MMMM yyyy", year_only="yyyy"),
),
"hendrix": Theme(
emphasis=Emphasis(
Expand All @@ -93,6 +93,6 @@ class Theme(BaseModel):
sep="•",
range_sep="➔",
rulechar="─",
datefmt=DateFormat(full="MMMM yyyy", year_only="MMMM yyyy"),
datefmt=DateFormat(full="MMMM yyyy", year_only="yyyy"),
),
}
10 changes: 8 additions & 2 deletions tests/test_data/resumes/full.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
"startDate": "1984-01-01",
"endDate": "1984-12-31",
"location": "Airstrip One, Oceania"
},
{
"name": "Droogle",
"startDate": "2002-12-31",
"endDate": "2014-12-31"
}
],
"volunteer": [
Expand Down Expand Up @@ -162,7 +167,7 @@
"url": "https://example.com/",
"area": "Computer Science",
"studyType": "Bachelor",
"startDate": "1999-10-01",
"startDate": "1999-12-31",
"endDate": "2013-01-01",
"score": "3.9",
"courses": [
Expand Down Expand Up @@ -549,7 +554,8 @@
"template": "Sequential",
"theme": "lollipop",
"ascii_only": false,
"language": "en"
"language": "en",
"dec31_as_year": true
}
}
}
102 changes: 102 additions & 0 deletions tests/visualization/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_ensure_single_trailing_newline(
"range_sep",
"present",
"collapse",
"dec31_as_year",
"expected",
],
[
Expand All @@ -61,6 +62,7 @@ def test_ensure_single_trailing_newline(
"-",
"present",
False,
False,
"",
),
(
Expand All @@ -71,6 +73,7 @@ def test_ensure_single_trailing_newline(
"-",
"present",
False,
False,
"- March 2900",
),
(
Expand All @@ -81,6 +84,7 @@ def test_ensure_single_trailing_newline(
"-",
"present",
False,
False,
"December 0163 - present",
),
(
Expand All @@ -91,6 +95,7 @@ def test_ensure_single_trailing_newline(
"-",
"today",
False,
False,
"January 2021 - today",
),
(
Expand All @@ -101,6 +106,7 @@ def test_ensure_single_trailing_newline(
"-",
"present",
False,
False,
"January 2021 - February 2021",
),
(
Expand All @@ -111,6 +117,7 @@ def test_ensure_single_trailing_newline(
"-",
"present",
False,
False,
"1999-04 - 2018-09",
),
(
Expand All @@ -121,6 +128,7 @@ def test_ensure_single_trailing_newline(
"***",
"present",
False,
False,
"1999-04 *** 2018-09",
),
(
Expand All @@ -131,6 +139,7 @@ def test_ensure_single_trailing_newline(
"***",
"heute",
False,
False,
"März 1999 *** Oktober 2018",
),
(
Expand All @@ -141,6 +150,7 @@ def test_ensure_single_trailing_newline(
"***",
"heute",
False,
False,
"marzo 1999 *** octubre 2018",
),
(
Expand All @@ -151,6 +161,7 @@ def test_ensure_single_trailing_newline(
"***",
"present",
True,
False,
"March 2018 *** April 2018",
),
(
Expand All @@ -161,8 +172,97 @@ def test_ensure_single_trailing_newline(
"***",
"present",
True,
False,
"April 2018",
),
(
None,
date(2000, 12, 31),
DateFormat(full="MMMM yyyy", year_only="yyyy"),
Locale("en"),
"---",
"present",
True,
True,
"--- 2000",
),
(
date(2000, 12, 31),
date(2000, 12, 31),
DateFormat(full="MMMM yyyy", year_only="yyyy"),
Locale("en"),
"---",
"present",
True,
True,
"2000",
),
(
date(2000, 12, 31),
None,
DateFormat(full="MMMM yyyy", year_only="yyyy"),
Locale("en"),
"---",
"present",
True,
True,
"2000 --- present",
),
(
date(2000, 12, 31),
date(2002, 12, 31),
DateFormat(full="MMMM yyyy", year_only="yyyy"),
Locale("en"),
"---",
"present",
True,
True,
"2000 --- 2002",
),
(
date(2000, 12, 30),
date(2002, 12, 30),
DateFormat(full="MMMM yyyy", year_only="yyyy"),
Locale("en"),
"---",
"present",
True,
True,
"December 2000 --- December 2002",
),
(
date(2000, 12, 31),
date(2002, 12, 31),
DateFormat(full="MMMM yyyy", year_only="yyyy"),
Locale("en"),
"---",
"present",
True,
False,
"December 2000 --- December 2002",
),
(
date(1995, 12, 31),
date(1999, 12, 31),
DateFormat(full="MMMM yyyy", year_only="''yy"),
Locale("en"),
"---",
"present",
True,
True,
"'95 --- '99",
),
(
date(1995, 12, 31),
date(1999, 12, 31),
DateFormat(full="MMMM yyyy", year_only="'Anno' yy"),
Locale("en"),
"to",
"present",
True,
True,
"Anno 95 to Anno 99",
),
],
)
def test_default_date_range(
Expand All @@ -173,6 +273,7 @@ def test_default_date_range(
range_sep: str,
present: str,
collapse: bool,
dec31_as_year: bool,
expected: str,
) -> None:
irrelevant = "."
Expand Down Expand Up @@ -211,6 +312,7 @@ def test_default_date_range(
),
locale=locale,
ascii_only=False,
dec31_as_year=dec31_as_year,
)
assert template.format_date_range(start, end, collapse) == expected

Expand Down

0 comments on commit 26d46cb

Please sign in to comment.