Esempio n. 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
Esempio n. 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 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
Esempio n. 3
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)
Esempio n. 4
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
Esempio n. 5
0
 def onOffset(cls, dt):
     first_weekday, _ = lib.monthrange(dt.year, dt.month)
     if first_weekday == 5:
         return dt.day == 3
     elif first_weekday == 6:
         return dt.day == 2
     else:
         return dt.day == 1
Esempio n. 6
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
Esempio n. 7
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)
Esempio n. 8
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)
Esempio n. 9
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
Esempio n. 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
Esempio n. 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 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
Esempio n. 12
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 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
Esempio n. 13
0
    def apply(self, other):
        other = datetime(other.year, other.month, other.day)

        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
Esempio n. 14
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
Esempio n. 15
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
Esempio n. 16
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)
Esempio n. 17
0
 def onOffset(cls, dt):
     __junk, days_in_month = lib.monthrange(dt.year, dt.month)
     return dt.day == days_in_month
Esempio n. 18
0
 def onOffset(cls, dt):
     firstDay, _ = lib.monthrange(dt.year, dt.month)
     return dt.day == (firstDay + 1)
Esempio n. 19
0
 def onOffset(cls, dt):
     __junk, days_in_month = lib.monthrange(dt.year, dt.month)
     return dt.day == days_in_month
Esempio n. 20
0
 def onOffset(cls, dt):
     days_in_month = lib.monthrange(dt.year, dt.month)[1]
     return dt.day == days_in_month
Esempio n. 21
0
 def onOffset(cls, dt):
     days_in_month = lib.monthrange(dt.year, dt.month)[1]
     return dt.day == days_in_month
Esempio n. 22
0
 def onOffset(cls, dt):
     firstDay, _ = lib.monthrange(dt.year, dt.month)
     return dt.day == (firstDay + 1)
Esempio n. 23
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
Esempio n. 24
0
 def _rollf(date):
     if (date.month != self.month
             or date.day < lib.monthrange(date.year, date.month)[1]):
         date = _increment(date)
     return date
Esempio n. 25
0
 def _rollf(date):
     if (date.month != self.month or
         date.day < lib.monthrange(date.year, date.month)[1]):
         date = _increment(date)
     return date
Esempio n. 26
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
Esempio n. 27
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)