Skip to content

Instantly share code, notes, and snippets.

@tcg
Created July 27, 2018 20:15
Show Gist options
  • Save tcg/021e3490e9f3eb2a15f0595061fe5e1e to your computer and use it in GitHub Desktop.
Save tcg/021e3490e9f3eb2a15f0595061fe5e1e to your computer and use it in GitHub Desktop.
Ended up not needing this. A Python Generator for getting a `datetime.date` for every day in a given year.
def _dates_for_year(year):
"""
A generator of all `datetime.date`s for a given integer year.
"""
if year != int(year):
raise ValueError(f"Year provided does not appear to be an integer. Provided: {year}")
for month in range(1, 12 + 1):
# Leaning on the calendar module to give the correct number of
# days for leap year February.
number_of_days = calendar.monthrange(year, month)[1]
for day in range(1, number_of_days + 1):
yield datetime.date(year, month, day)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment