mikeckennedy/python-jumpstart-course-demos

Birthday app exception when born on 29th Feb

SpacedMonkeyTCT opened this issue · 6 comments

Exception occurs when making the date of the birthday in this year but it is not a leap year.

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).

screen shot 2018-06-19 at 8 45 05 am

isn't the problem with feb 29th?

image
I get the exception too, but it's normal right? (since 2018 doesn't have a feb 29th)

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

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

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.