Include local names on holiday list

Closes: #106
This commit is contained in:
Edward Betts 2024-01-16 16:22:04 +00:00
parent 75d18aed2b
commit b33da8485c
3 changed files with 22 additions and 3 deletions

View file

@ -60,15 +60,24 @@ def get_nyse_holidays(
def get_holidays(country: str, start_date: date, end_date: date) -> list[Holiday]: def get_holidays(country: str, start_date: date, end_date: date) -> list[Holiday]:
"""Get holidays.""" """Get holidays."""
found: list[Holiday] = [] found: list[Holiday] = []
uc_country = country.upper()
holiday_country = getattr(holidays, uc_country)
default_language = holiday_country.default_language
for year in range(start_date.year, end_date.year + 1): for year in range(start_date.year, end_date.year + 1):
hols = holidays.country_holidays(country.upper(), years=year, language="en_US") en_hols = holidays.country_holidays(uc_country, years=year, language="en_US")
local_lang = holidays.country_holidays(
uc_country, years=year, language=default_language
)
found += [ found += [
Holiday( Holiday(
date=hol_date, date=hol_date,
name=title, name=title,
local_name=local_lang[hol_date],
country=country.lower(), country=country.lower(),
) )
for hol_date, title in hols.items() for hol_date, title in en_hols.items()
if start_date < hol_date < end_date if start_date < hol_date < end_date
] ]

View file

@ -91,6 +91,16 @@ class Holiday:
name: str name: str
country: str country: str
date: datetime.date date: datetime.date
local_name: str | None = None
@property
def display_name(self) -> str:
"""Format name for display."""
return (
f"{self.name} ({self.local_name})"
if self.local_name and self.local_name != self.name
else self.name
)
emojis = { emojis = {

View file

@ -14,7 +14,7 @@
<td></td> <td></td>
{% endif %} {% endif %}
<td>{{ country.flag }} {{ country.name }}</td> <td>{{ country.flag }} {{ country.name }}</td>
<td>{{ item.name }}</td> <td>{{ item.display_name }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>