Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend HolidayBase::__setitem__ to handle names including '; ' #1858

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion holidays/holiday_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ def __setitem__(self, key: DateLike, value: str) -> None:
# If there are multiple holidays on the same date
# order their names alphabetically.
holiday_names = set(self[key].split(HOLIDAY_NAME_DELIMITER))
holiday_names.add(value)
for holiday_name in value.split(HOLIDAY_NAME_DELIMITER):
holiday_names.add(holiday_name)
arkid15r marked this conversation as resolved.
Show resolved Hide resolved
value = HOLIDAY_NAME_DELIMITER.join(sorted(holiday_names))

dict.__setitem__(self, self.__keytransform__(key), value)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_holiday_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,10 @@ def test_setitem(self):
self.assertIn("2014-01-03", self.hb)
self.assertEqual(self.hb["2014-01-03"], "Custom Holiday")

self.hb["2014-01-04"] = "Custom Holiday"
self.hb["2014-01-04"] = "Custom Holiday; Another Custom Holiday"
self.assertEqual(self.hb["2014-01-04"], "Another Custom Holiday; Custom Holiday")

def test_update(self):
self.hb.update(
{
Expand Down