diff --git a/c3l_membership/utils.py b/c3l_membership/utils.py new file mode 100644 --- /dev/null +++ b/c3l_membership/utils.py @@ -0,0 +1,15 @@ +from datetime import date + + +def calculate_age(birthday): + today = date.today() + born = birthday + try: + birthday = born.replace(year=today.year) + except ValueError: + birthday = born.replace(year=today.year, month=born.month + 1, day=1) + + age = today.year - born.year + if birthday > today: + age -= 1 + return age