botant / py-business-calendar

Business days and custom calendar calculations for Python
MIT License
26 stars 11 forks source link

busdaycount can cause infinite loop #1

Closed naro closed 8 years ago

naro commented 9 years ago

calendar.busdaycount(wednesday, saturday) causes infinite loop in _workdaycount method, because date2wd is 5 (saturday) but self.weekdaymap[date1wd].nextworkday sets date1wd to 0 (Monday) as soon as the loop hits Friday so it never reaches to situation when date1wd == 5(Saturday)

Related code: https://github.com/antoniobotelho/py-business-calendar/blob/master/business_calendar/business_calendar.py#L412

self.weekdaymap is:

[DayOfWeek(dayofweek=0, isworkday=True, nextworkday=1, offsetnext=1, prevworkday=4, offsetprev=-3),
 DayOfWeek(dayofweek=1, isworkday=True, nextworkday=2, offsetnext=1, prevworkday=0, offsetprev=-1),
 DayOfWeek(dayofweek=2, isworkday=True, nextworkday=3, offsetnext=1, prevworkday=1, offsetprev=-1),
 DayOfWeek(dayofweek=3, isworkday=True, nextworkday=4, offsetnext=1, prevworkday=2, offsetprev=-1),
 DayOfWeek(dayofweek=4, isworkday=True, nextworkday=0, offsetnext=3, prevworkday=3, offsetprev=-1),
 DayOfWeek(dayofweek=5, isworkday=False, nextworkday=0, offsetnext=2, prevworkday=4, offsetprev=-1),
 DayOfWeek(dayofweek=6, isworkday=False, nextworkday=0, offsetnext=1, prevworkday=4, offsetprev=-2)]
botant commented 8 years ago

Hi Radim, thanks for reporting. Belatedly, but I'm fixing this now.