Exemple #1
0
    def _verify_holiday(self, dt):
        move_day = None
        weekday = dt.weekday()

        is_weekend = not self._weekdays[weekday]

        idiosyncratic, name, move = self._is_idiosyncratic(dt)
        # No move rules for idiosyncratic holidays?
        if idiosyncratic:
            return True, name, None

        if dt.month in self._dated_holidays:
            holiday_day_descriptions = self._dated_holidays[dt.month]
            if dt.day in holiday_day_descriptions:
                name, move = holiday_day_descriptions[dt.day]
                if move is not None and is_weekend:
                    move_day = self._move_holiday(dt, move)
                return True, name, move_day

        if len(self._numbered_weekday_holidays[dt.month]) > 0:
            for tup in self._numbered_weekday_holidays[dt.month]:
                order, weekday, name = tup
                # n-th day of the month holidays are usually not moved
                # as they always happen on a particular day of the week
                if dt.weekday() == weekday:
                    if order > 0 and (((dt.day-1)//dateutils.DAYS_IN_WEEK+1) == order):
                        return True, name, None
                    if order == -1:
                        # last weekday of the month
                        eom_day = dateutils.eom(dt.year, dt.month)
                        if dt == weekday_on_or_before(eom_day, weekday):
                            return True, name, None

        # if everything else in other categories does not work - check if it is weekend
        if is_weekend:
            return True, 'weekend', None

        return False, '', move_day
    def _verify_holiday(self, dt):
        move_day = None
        weekday = dt.weekday()

        is_weekend = not self._weekdays[weekday]

        idiosyncratic, name, move = self._is_idiosyncratic(dt)
        # No move rules for idiosyncratic holidays?
        if idiosyncratic:
            return True, name, None

        if dt.month in self._dated_holidays:
            holiday_day_descriptions = self._dated_holidays[dt.month]
            if dt.day in holiday_day_descriptions:
                name, move = holiday_day_descriptions[dt.day]
                if move is not None and is_weekend:
                    move_day = self._move_holiday(dt, move)
                return True, name, move_day

        if len(self._numbered_weekday_holidays[dt.month]) > 0:
            for tup in self._numbered_weekday_holidays[dt.month]:
                order, weekday, name = tup
                # n-th day of the month holidays are usually not moved
                # as they always happen on a particular day of the week
                if dt.weekday() == weekday:
                    if order > 0 and (((dt.day-1)//dateutils.DAYS_IN_WEEK+1) == order):
                        return True, name, None
                    if order == -1:
                        # last weekday of the month
                        eom_day = dateutils.eom(dt.year, dt.month)
                        if dt == weekday_on_or_before(eom_day, weekday):
                            return True, name, None

        # if everything else in other categories does not work - check if it is weekend
        if is_weekend:
            return True, 'weekend', None

        return False, '', move_day
def lbusdate(year, month, calendar):
    """ Last business day of the month
    """
    dt = dateutils.eom(year, month)
    return _roll_backward(dt, calendar)
Exemple #4
0
def lbusdate(year, month, calendar):
    """ Last business day of the month
    """
    dt = dateutils.eom(year, month)
    return _roll_backward(dt, calendar)