Esempio n. 1
0
def next_bday(date):
    """
    Return next bday which it is not holidays or offdays
    :param date: str
    :return: datetime
    """
    add_day = 1
    next_bday = datetime.strptime(date, "%Y-%m-%d") + BDay(add_day)
    # check it is not holiday
    while is_holiday(date=next_bday.strftime("%Y-%m-%d")) or is_offdays(date=next_bday.strftime("%m/%d/%y")):
        add_day += 1
        next_bday = datetime.strptime(date, "%Y-%m-%d") + BDay(add_day)

    return next_bday.strftime("%Y-%m-%d")
Esempio n. 2
0
    def move_bday(date, day):
        """
        Return next bday which it is not holidays or offdays
        :param date: str or datetime
        :param day: int (positive or negative)
        :return: datetime
        """
        if type(date) == str:
            date = datetime.strptime(date, '%Y-%m-%d')

        next_bday = date + BDay(day)
        # check it is not holiday
        while is_holiday(date=next_bday.strftime('%Y-%m-%d')) \
                or is_offdays(date=next_bday.strftime('%m/%d/%y')):
            day += 1 if day > 0 else -1
            next_bday = date + BDay(day)

        return next_bday.to_datetime()
Esempio n. 3
0
    def test_move_bday(self):
        """
        Test next bday that skip holidays and offdays
        """
        print 'using date: %s' % self.date

        for day in [1, -1]:
            print 'run next_bday...'
            next_bday = self.profiler.move_bday(self.date, day)
            """:type: datetime"""

            print 'get result: %s' % next_bday

            self.assertEqual(type(next_bday), datetime)
            self.assertNotEqual(self.date, next_bday)

            self.assertFalse(is_holiday(next_bday))
            self.assertFalse(is_offdays(next_bday))

            print '.' * 60
Esempio n. 4
0
    def test_move_bday(self):
        """
        Test next bday that skip holidays and offdays
        """
        print "using date: %s" % self.date

        for day in [1, -1]:
            print "run next_bday..."
            next_bday = self.profiler.move_bday(self.date, day)
            """:type: datetime"""

            print "get result: %s" % next_bday

            self.assertEqual(type(next_bday), datetime)
            self.assertNotEqual(self.date, next_bday)

            self.assertFalse(is_holiday(next_bday))
            self.assertFalse(is_offdays(next_bday))

            print "." * 60