<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _end_apply_index(self, dtindex):
 """ Add self to the given DatetimeIndex, specialized for case where self.weekday is non-null. Parameters dtindex : DatetimeIndex Returns ------- result : DatetimeIndex """

        off = dtindex.to_perioddelta('D')

        base, mult = libfrequencies.get_freq_code(self.freqstr)
        base_period = dtindex.to_period(base)
        if not isinstance(base_period._data, np.ndarray):
            # unwrap PeriodIndex --> PeriodArray
            base_period = base_period._data

        if self.n > 0:
            # when adding, dates on end roll to next
            normed = dtindex - off + Timedelta(1, 'D') - Timedelta(1, 'ns')
            roll = np.where(base_period.to_timestamp(how='end') == normed,
                            self.n, self.n - 1)
            # integer-array addition on PeriodIndex is deprecated,
            #  so we use _addsub_int_array directly
            shifted = base_period._addsub_int_array(roll, operator.add)
            base = shifted.to_timestamp(how='end')
        else:
            # integer addition on PeriodIndex is deprecated,
            #  so we use _time_shift directly
            roll = self.n
            base = base_period._time_shift(roll).to_timestamp(how='end')

        return base + off + Timedelta(1, 'ns') - Timedelta(1, 'D')