Birthday app exception when born on 29th Feb
SpacedMonkeyTCT opened this issue · 6 comments
SpacedMonkeyTCT commented
Exception occurs when making the date of the birthday in this year but it is not a leap year.
mikeckennedy commented
Hi @SpacedMonkeyTCT Can you send me a date for which this fails? I tried it this year and it worked fine (it's not a leap year).
smartel99 commented
isn't the problem with feb 29th?
smartel99 commented
mikeckennedy commented
Yeah, not much you can do here. This is Python's way of validating the data. Just have to put the input section into a try / except
try:
# do that stuff
except ValueError:
# print error message, try again
SpacedMonkeyTCT commented
I used a valid date of birth. It's the alteration made to the date to calculate your birthday this year.
---------------------------
BIRTHDAY APP
---------------------------
When were you born?
Year [YYYY]: 2000
Month [MM]: 02
Day [DD]: 29
Traceback (most recent call last):
File "program.py", line 45, in <module>
main()
File "program.py", line 41, in main
number_of_days = compute_days_between_dates(bday, today)
File "program.py", line 22, in compute_days_between_dates
this_year = datetime.date(target_date.year, original_date.month, original_date.day)
ValueError: day is out of range for month
mikeckennedy commented
I see. It was a leap year when born, but not this year too. I guess you would need to add a special check the compute days between dates. If it's not a leap year and it is Feb 29, then use March 1 instead.