如果日期是假日,则添加日期,直到日期为假日

时间:2017-08-05 06:51:16

标签: python date

如果某一天x是假日,则将days添加到日x,直到它不是假日。

def is_lastday_holiday(lastday):
   while lastday in sorted(holidays.AT(years=2017)):
      lastday + timedelta(days=1)
   return lastday

这导致无限循环。任何提示?

1 个答案:

答案 0 :(得分:3)

您错过了分配和更新lastday

def is_lastday_holiday(lastday):  
    while lastday in sorted(holidays.AT(years=2017)):  
        lastday = lastday + timedelta(days=1) 
    return lastday

或者,

lastday += timedelta(days=1)