I have to return the day of the year (int) for a given string date (e.g. "September, 14, 2019") WITHOUT using datetime. I also have to make it basic enough to where I can make two other similar functions for different calendars.
This is what I had before:
def date_to_day_of_year(self, month, day, year):
'''
Given the month, day and year of a date,
return the number of the day in the year.
'''
day_of_year = 0
for month_name, days_in_month in month_days.items():
if month_name == month:
break
day_of_year += days_in_month
day_of_year += day
if self.is_leap_year(year) and ((month != 'Feb') and (month != 'Jan')):
day_of_year += 1
return day_of_year(month, day, year)
But I just can't seem to convert it into this:
def day_of_year_to_date(self, day_of_year, year):
'''
Convert day of year to date.
'''
# ...