org.models.swiss_holidays

Attributes

CANTONS

Classes

SwissHolidays

Provides the ability to check dates against Swiss holidays and to

Module Contents

org.models.swiss_holidays.CANTONS[source]
class org.models.swiss_holidays.SwissHolidays(cantons: Iterable[str] = (), other: Iterable[tuple[int, int, str]] = (), timezone: str = 'Europe/Zurich')[source]

Provides the ability to check dates against Swiss holidays and to list the holidays for a given year. Builds on the code from python-holidays.

See the Switzerland class here: https://github.com/dr-prodigy/python-holidays/blob/master/holidays.py

Supports the following features which are not provided by python-holidays:

  • Translatable strings.

  • The ability to combine cantons.

  • The ability to add extra holidays for specific days of any year.

The interface is inspired by pyhton-holidays, thought he API surface is a bit smaller and there is less magic.

_cantons: set[str][source]
_other: dict[tuple[int, int], set[str]][source]
add_canton(canton: str) None[source]
add_holiday(month: int, day: int, description: str) None[source]
__bool__() bool[source]
__contains__(dt: datetime.date | datetime.datetime) bool[source]
all(year: int) list[tuple[datetime.date, list[str]]][source]

Returns all the holidays for the given year for the current set of cantons. If no cantons are selected and no other holidays are defined, nothing is returned.

The result is a list in chronological order with each list entry being at tuple of date and at least one description (if multiple holidays are on a single day, a list of descriptions is returned).

The list of descriptions is sorted alphabetically.

between(start: datetime.date | datetime.datetime, end: datetime.date | datetime.datetime) list[tuple[datetime.date, list[str]]][source]

Returns all the holidays between the given start and end date in the same manner ass all().

other(year: int) Iterator[tuple[date, set[str]]][source]

Returns all custom defined holidays for the given year.

official(year: int) Iterator[tuple[date, tuple[str, ...]]][source]

Like all(), but only includes the official holidays, not the custom defined ones.

If no cantons are selected, no official holidays are returned, not even the national ones.

The description only ever contains a tuple with one item. This is for congruence with the other methods of this class, where the description is always in an iterable (not necessarily a tuple).