Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
Add handling for leap day birthdays
Browse files Browse the repository at this point in the history
We've been getting a ValueError for day out of range errors when a leap day birthday is entered in a non-leap year. This handles that error.
  • Loading branch information
Hillary Jeffrey committed May 14, 2018
1 parent 54cbfbc commit 1904aa1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion retirement_api/utils/ss_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ def get_months_past_birthday(dob):
def get_months_until_next_birthday(dob):
"""return number of months until next birthday, with a minimum of 1 """
today = datetime.date.today()
bday_this_year = datetime.date(today.year, dob.month, dob.day)
try:
bday_this_year = datetime.date(today.year, dob.month, dob.day)
except ValueError:
# Handle Leap Day birthdays
bday_this_year = datetime.date(today.year, dob.month, dob.day - 1)

if today >= bday_this_year:
return (12 - today.month) + dob.month
elif today < bday_this_year:
Expand Down

0 comments on commit 1904aa1

Please sign in to comment.