Add time.date_range() convenience function

This commit is contained in:
Lance Edgar 2017-11-12 09:49:34 -06:00
parent e2c6caf7d4
commit 61086c2442

View file

@ -170,3 +170,13 @@ def last_of_month(date):
""" """
last_day = calendar.monthrange(date.year, date.month)[1] last_day = calendar.monthrange(date.year, date.month)[1]
return date.replace(day=last_day) return date.replace(day=last_day)
def date_range(start, end, step=1):
"""
Generator which yields all dates between ``start`` and ``end``, *inclusive*.
"""
date = start
while date <= end:
yield date
date += datetime.timedelta(days=step)