Пример #1
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = lib.monthrange(other.year, self.month)
        lastBDay = (days_in_month -
                    max(((wkday + days_in_month - 1) % 7) - 4, 0))

        years = n
        if n > 0:
            if (other.month < self.month or
                (other.month == self.month and other.day < lastBDay)):
                years -= 1
        elif n <= 0:
            if (other.month > self.month or
                (other.month == self.month and other.day > lastBDay)):
                years += 1

        other = other + relativedelta(years=years)

        _, days_in_month = lib.monthrange(other.year, self.month)
        result = datetime(other.year, self.month, days_in_month,
                          other.hour, other.minute, other.second,
                          other.microsecond)

        if result.weekday() > 4:
            result = result - BDay()

        return result
Пример #2
0
    def apply(self, other):
        n = self.n

        wkday, _ = lib.monthrange(other.year, other.month)

        first = _get_firstbday(wkday)

        monthsSince = (other.month - self.startingMonth) % 3
        if monthsSince == 3: # on offset
            monthsSince = 0

        if n <= 0 and monthsSince != 0: # make sure to roll forward so negate
            monthsSince = monthsSince - 3

        # roll forward if on same month later than first bday
        if n <= 0 and (monthsSince == 0 and other.day > first):
            n = n + 1
        # pretend to roll back if on same month but before firstbday
        elif n > 0 and (monthsSince == 0 and other.day < first):
            n = n - 1

        # get the first bday for result
        other = other + relativedelta(months=3*n - monthsSince)
        wkday, _ = lib.monthrange(other.year, other.month)
        first = _get_firstbday(wkday)
        result = datetime(other.year, other.month, first,
                          other.hour, other.minute, other.second,
                          other.microsecond)
        return result
Пример #3
0
    def apply(self, other):
        n = self.n

        wkday, _ = lib.monthrange(other.year, other.month)
        first = _get_firstbday(wkday)

        if other.day > first and n<=0:
            # as if rolled forward already
            n += 1

        other = other + relativedelta(months=n)
        wkday, _ = lib.monthrange(other.year, other.month)
        first = _get_firstbday(wkday)
        result = datetime(other.year, other.month, first)
        return result
Пример #4
0
 def _increment(date):
     if date.month == self.month:
         _, days_in_month = lib.monthrange(date.year, self.month)
         if date.day != days_in_month:
             year = date.year
         else:
             year = date.year + 1
     elif date.month < self.month:
         year = date.year
     else:
         year = date.year + 1
     _, days_in_month = lib.monthrange(year, self.month)
     return datetime(year, self.month, days_in_month,
                     date.hour, date.minute, date.second,
                     date.microsecond)
Пример #5
0
 def apply(self, other):
     n = self.n
     _, days_in_month = lib.monthrange(other.year, other.month)
     if other.day != days_in_month:
         other = other + relativedelta(months=-1, day=31)
         if n <= 0:
             n = n + 1
     other = other + relativedelta(months=n, day=31)
     return other
Пример #6
0
 def apply(self, other):
     n = self.n
     wkday, days_in_month = lib.monthrange(other.year, self.month)
     if other.month != self.month or other.day != days_in_month:
         other = datetime(other.year - 1, self.month, days_in_month,
                          other.hour, other.minute, other.second,
                          other.microsecond)
         if n <= 0:
             n = n + 1
     other = other + relativedelta(years=n)
     return other
Пример #7
0
    def _partial_date_slice(self, reso, parsed):
        if not self.is_monotonic:
            raise TimeSeriesError("Partial indexing only valid for ordered time" " series")

        if reso == "year":
            t1 = Timestamp(datetime(parsed.year, 1, 1))
            t2 = Timestamp(datetime(parsed.year, 12, 31))
        elif reso == "month":
            d = lib.monthrange(parsed.year, parsed.month)[1]
            t1 = Timestamp(datetime(parsed.year, parsed.month, 1))
            t2 = Timestamp(datetime(parsed.year, parsed.month, d))
        elif reso == "quarter":
            qe = (((parsed.month - 1) + 2) % 12) + 1  # two months ahead
            d = lib.monthrange(parsed.year, qe)[1]  # at end of month
            t1 = Timestamp(datetime(parsed.year, parsed.month, 1))
            t2 = Timestamp(datetime(parsed.year, qe, d))
        else:
            raise KeyError

        stamps = self.asi8
        left = stamps.searchsorted(t1.value, side="left")
        right = stamps.searchsorted(t2.value, side="right")
        return slice(left, right)
Пример #8
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = lib.monthrange(other.year, other.month)

        monthsToGo = 3 - ((other.month - self.startingMonth) % 3)
        if monthsToGo == 3:
            monthsToGo = 0

        if n > 0 and not (other.day >= days_in_month and monthsToGo == 0):
            n = n - 1

        other = other + relativedelta(months=monthsToGo + 3*n, day=31)

        return other
Пример #9
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = lib.monthrange(other.year, self.month)

        first = _get_firstbday(wkday)

        years = n


        if n > 0: # roll back first for positive n
            if (other.month < self.month or
                (other.month == self.month and other.day < first)):
                years -= 1
        elif n <= 0: # roll forward
            if (other.month > self.month or
                (other.month == self.month and other.day > first)):
                years += 1

        # set first bday for result
        other = other + relativedelta(years = years)
        wkday, days_in_month = lib.monthrange(other.year, self.month)
        first = _get_firstbday(wkday)
        return datetime(other.year, self.month, first)
Пример #10
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = lib.monthrange(other.year, other.month)
        lastBDay = days_in_month - max(((wkday + days_in_month - 1) % 7) - 4, 0)

        if n > 0 and not other.day >= lastBDay:
            n = n - 1
        elif n <= 0 and other.day > lastBDay:
            n = n + 1
        other = other + relativedelta(months=n, day=31)

        if other.weekday() > 4:
            other = other - BDay()
        return other
Пример #11
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = lib.monthrange(other.year, other.month)

        monthsSince = (other.month - self.startingMonth) % 3

        if monthsSince == 3: # on an offset
            monthsSince = 0

        if n <= 0 and monthsSince != 0:
            # make sure you roll forward, so negate
            monthsSince = monthsSince - 3

        if n < 0 and (monthsSince == 0 and other.day > 1):
            # after start, so come back an extra period as if rolled forward
            n = n + 1

        other = other + relativedelta(months=3*n - monthsSince, day=1)
        return other
Пример #12
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = lib.monthrange(other.year, other.month)
        lastBDay = days_in_month - max(((wkday + days_in_month - 1) % 7) - 4, 0)

        monthsToGo = 3 - ((other.month - self.startingMonth) % 3)
        if monthsToGo == 3:
            monthsToGo = 0

        if n > 0 and not (other.day >= lastBDay and monthsToGo == 0):
            n = n - 1
        elif n <= 0 and other.day > lastBDay and monthsToGo == 0:
            n = n + 1

        other = other + relativedelta(months=monthsToGo + 3*n, day=31)

        if other.weekday() > 4:
            other = other - BDay()

        return other
Пример #13
0
 def onOffset(self, dt):
     wkday, days_in_month = lib.monthrange(dt.year, self.month)
     return self.month == dt.month and dt.day == days_in_month
Пример #14
0
 def _rollf(date):
     if (date.month != self.month or
         date.day < lib.monthrange(date.year, date.month)[1]):
         date = _increment(date)
     return date
Пример #15
0
 def _decrement(date):
     year = date.year if date.month > self.month else date.year - 1
     _, days_in_month = lib.monthrange(year, self.month)
     return datetime(year, self.month, days_in_month,
                     date.hour, date.minute, date.second,
                     date.microsecond)
Пример #16
0
 def onOffset(cls, dt):
     __junk, days_in_month = lib.monthrange(dt.year, dt.month)
     return dt.day == days_in_month
Пример #17
0
 def onOffset(cls, dt):
     firstDay, _ = lib.monthrange(dt.year, dt.month)
     return dt.day == (firstDay + 1)