You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

18 lines
495 B

from datetime import datetime, timedelta
from collections import Counter
def date_range(start, end):
if isinstance(start, datetime):
start = start.date()
if isinstance(end, datetime):
end = end.date()
delta = end - start
for d in range(delta.days + 1):
yield start + timedelta(days=d)
return
def weekday_in_date_range(start, end, weekday):
counter = Counter([d.isoweekday() for d in date_range(start, end)])
return counter.get(weekday, 0)