Beispiel #1
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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 = tslib.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
Beispiel #2
0
    def apply(self, other):
        n = self.n

        wkday, _ = tslib.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, _ = tslib.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
Beispiel #3
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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 = tslib.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
Beispiel #4
0
    def apply(self, other):
        n = self.n

        wkday, _ = tslib.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, _ = tslib.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
Beispiel #5
0
 def _increment(date):
     if date.month == self.month:
         _, days_in_month = tslib.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 = tslib.monthrange(year, self.month)
     return datetime(year, self.month, days_in_month, date.hour, date.minute, date.second, date.microsecond)
Beispiel #6
0
 def _increment(date):
     if date.month == self.month:
         _, days_in_month = tslib.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 = tslib.monthrange(year, self.month)
     return datetime(year, self.month, days_in_month, date.hour,
                     date.minute, date.second, date.microsecond)
Beispiel #7
0
 def onOffset(cls, dt):
     first_weekday, _ = tslib.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
Beispiel #8
0
 def onOffset(cls, dt):
     first_weekday, _ = tslib.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
Beispiel #9
0
    def apply(self, other):
        n = self.n

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

        if other.day > first and n <= 0:
            # as if rolled forward already
            n += 1
        elif other.day < first and n > 0:
            other = other + timedelta(days=first - other.day)
            n -= 1

        other = other + relativedelta(months=n)
        wkday, _ = tslib.monthrange(other.year, other.month)
        first = _get_firstbday(wkday)
        result = datetime(other.year, other.month, first)
        return result
Beispiel #10
0
    def apply(self, other):
        n = self.n

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

        if other.day > first and n <= 0:
            # as if rolled forward already
            n += 1
        elif other.day < first and n > 0:
            other = other + timedelta(days=first - other.day)
            n -= 1

        other = other + relativedelta(months=n)
        wkday, _ = tslib.monthrange(other.year, other.month)
        first = _get_firstbday(wkday)
        result = datetime(other.year, other.month, first)
        return result
Beispiel #11
0
    def apply(self, other):
        other = datetime(other.year, other.month, other.day)

        n = self.n
        _, days_in_month = tslib.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
Beispiel #12
0
    def apply(self, other):
        other = datetime(other.year, other.month, other.day)

        n = self.n
        _, days_in_month = tslib.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
Beispiel #13
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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 = tslib.monthrange(other.year, self.month)
        first = _get_firstbday(wkday)
        return datetime(other.year, self.month, first)
Beispiel #14
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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 = tslib.monthrange(other.year, self.month)
        first = _get_firstbday(wkday)
        return datetime(other.year, self.month, first)
Beispiel #15
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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
Beispiel #16
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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
Beispiel #17
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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
Beispiel #18
0
    def apply(self, other):
        other = datetime(other.year, other.month, other.day)

        n = self.n

        wkday, days_in_month = tslib.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
Beispiel #19
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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
Beispiel #20
0
    def apply(self, other):
        other = datetime(other.year, other.month, other.day)

        n = self.n

        wkday, days_in_month = tslib.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
Beispiel #21
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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
Beispiel #22
0
    def apply(self, other):
        n = self.n

        wkday, days_in_month = tslib.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
Beispiel #23
0
 def _decrement(date):
     year = date.year if date.month > self.month else date.year - 1
     _, days_in_month = tslib.monthrange(year, self.month)
     return datetime(year, self.month, days_in_month,
                     date.hour, date.minute, date.second,
                     date.microsecond)
Beispiel #24
0
 def _decrement(date):
     year = date.year if date.month > self.month else date.year - 1
     _, days_in_month = tslib.monthrange(year, self.month)
     return datetime(year, self.month, days_in_month, date.hour,
                     date.minute, date.second, date.microsecond)
Beispiel #25
0
 def _rollf(date):
     if (date.month != self.month or
             date.day < tslib.monthrange(date.year, date.month)[1]):
         date = _increment(date)
     return date
Beispiel #26
0
 def onOffset(cls, dt):
     days_in_month = tslib.monthrange(dt.year, dt.month)[1]
     return dt.day == days_in_month
Beispiel #27
0
 def _rollf(date):
     if (date.month != self.month
             or date.day < tslib.monthrange(date.year, date.month)[1]):
         date = _increment(date)
     return date
Beispiel #28
0
 def onOffset(self, dt):
     wkday, days_in_month = tslib.monthrange(dt.year, self.month)
     return self.month == dt.month and dt.day == days_in_month
Beispiel #29
0
 def onOffset(self, dt):
     wkday, days_in_month = tslib.monthrange(dt.year, self.month)
     return self.month == dt.month and dt.day == days_in_month
Beispiel #30
0
 def onOffset(cls, dt):
     days_in_month = tslib.monthrange(dt.year, dt.month)[1]
     return dt.day == days_in_month