Draft

Age Calculator

Description:

Make an age calculator which given a date of birth parameter returns the current age in years, months and days, as well as the time remaining for the next birthday in the same units.

The two results must be separated by a newline escape character.

# String Format:
"Your age is x year/s, y month/s and z day/s.\n
y month/s and z day/s remaining for your birthday."

The month measure mustn't be higher than 11, and the day measure mustn't be higher than the amount of days in that month. The purpose of this is to provide a "simpler" way for the user to read the result. For example:

"1 month and 64 days remaining for your birthday." #=> Wrong
"3 months and 4 days remaining for your birthday." #=> Correct

# Time from January 1st to April 1st.
"2 months and 31 days remaining for your birthday." #=> Wrong
"3 months and 0 days remaining for your birthday." #=> Correct

# Time from December 1st to March 1st in a non-leap year.
"2 months and 28 days remaining for your birthday." #=> Wrong
"3 months and 0 days remaining for your birthday." #=> Correct

An easy way to look at this, is that the age and the remaining time always have to add up to 12 months and 0 days.

The units must also reflect whether the measure is singular or plural. For example: 1 year, 0 months and 2 days.

Additionally, if the current time happens to match the birthday of the test case, you should replace the last line with "Happy Birthday"!

# If today is the birthday:
"Your age is x year/s, y month/s and z day/s.\n
Happy Birthday!"

If a person hasn't been born as of the current time (i.e. the date of birth is greater than the current date) then you must return:

# If they haven't been born:
"You haven't been born!"

For the sake of the tests made in this Kata, the "time" will be set to June 15th of 2200. So, you will calculate age as of this date.

Indications:

  • This Kata uses ISO 8601 (YYYY-MM-DD) date format,
  • Use the real amount of days for every month, as well as considering leap years.
  • Don't change the "time" variable, otherwise your tests will show a wrong result.

Preloaded Libraries:

  • Ruby: date
  • C++: ctime

Examples:

calculate_age("2002-12-20") #=>

"Your age is 197 years, 5 months and 25 days.\n
6 months and 5 days remaining for your birthday."
calculate_age("2002-06-15") #=>

"Your age is 198 years, 0 months and 0 days.\n
Happy Birthday!"
Algorithms

Stats:

CreatedJul 2, 2021
Warriors Trained85
Total Skips11
Total Code Submissions165
Total Times Completed7
Ruby Completions5
C++ Completions4
Total Stars4
% of votes with a positive feedback rating13% of 4
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes3
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • Chiispiitas Avatar
Ad