How to use the holidays.CountryHoliday function in holidays

To help you get started, we’ve selected a few holidays examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github InsightLab / PyMove / pymove / utils / datetime.py View on Github external
if true, means that the day informed by the user is a working day.
        if false, means that the day is not a working day.

    References
    ----------
    Countries and States names available in https://pypi.org/project/holidays/
    """
    result = True

    if isinstance(dt, str):
        dt = date_to_str(dt)

    if isinstance(dt, datetime.datetime):
        dt = datetime.date(dt.year, dt.month, dt.day)

    if dt in holidays.CountryHoliday(country=country, prov=None, state=state):
        result = False
    else:
        dow = to_day_of_week_int(dt)
        # 5 == saturday, 6 == sunday
        if dow == 5 or dow == 6:
            result = False

    return result
github octoenergy / timeserio / timeserio / preprocessing / datetime.py View on Github external
def get_is_holiday_from_series(
    series: pd.Series, country: str = "UnitedKingdom"
) -> pd.Series:
    """Return 1 if day is a public holiday.

    By default, uses UK holidays, but can specify a country by string name in
    `country` arg. See `holidays.list_supported_countries()` for list of
    supported countries.
    """
    years = series.dt.year.unique()
    holiday_dates = holidays.CountryHoliday(country, years=years)
    return series.dt.date.isin(holiday_dates).astype(int)
github bruxy70 / Garbage-Collection / custom_components / garbage_collection / sensor.py View on Github external
self.__prov,
                self.__state,
                self.__observed,
            )
            kwargs = {"years": years}
            if self.__state is not None and self.__state != "":
                kwargs["state"] = self.__state
            if self.__prov is not None and self.__prov != "":
                kwargs["prov"] = self.__prov
            if (
                self.__observed is not None
                and type(self.__observed) == bool
                and self.__observed == False
            ):
                kwargs["observed"] = self.__observed
            hol = holidays.CountryHoliday(self.__country_holidays, **kwargs).items()
            try:
                for d, name in hol:
                    if d >= today:
                        self.__holidays.append(d)
                        holidays_log += f"\n  {d}: {name}"
            except KeyError:
                _LOGGER.error(
                    "(%s) Invalid country code (%s)",
                    self.__name,
                    self.__country_holidays,
                )
            _LOGGER.debug("(%s) Found these holidays: %s", self.__name, holidays_log)