• ScottPletcher - Tuesday, February 27, 2018 9:16 AM

    As usual with age, leap year birthdays are the deciding factor.

    If someone was born on Feb 29, 2004, how old are they on Feb 28, 2018?  In your code, 13.  But in some jurisdictions, legally that person is 14 on Feb 28.  In other jurisdictions, you can use Mar-1 as their birthday in non-leap years.

    Edit: Btw, get rid of the variable in the function, it adds slight overhead unnecessarily:

    Hi Scott,

    Thanks for your comments!

    My function gets the correct age, but I agree, there will always be one-off business rules to be applied.  In your leap-year example, the age would not be augmented, instead, the rule would be applied outside the function.  For example, a jurisdiction such as you mentioned would not alter a subjects age, but they might allow the subject to buy beer at 20 if non-leap year, and date is Feb 28, and subject DOB is Feb 29.  Heck, I could pass a law that grants you the grandpa discount if your dog has pups, but that wouldn't actually make you a grandpa - and your subject is still 20 on Feb 28.

    I agree, the variable is not needed.  More of a style issue where I normally use vars to standardize return values across functions.  You might be surprised, but benchmarks won't improve measurably by removing this var.  Note, this is not interpreted code.