easy +10 pts

Age in years months days

Compute a person's exact age broken into years, months, and days from a birthdate to a reference date.

Write a function `age_years_months_days(birth_date: str, reference_date: str) -> dict` that takes two date strings in `YYYY-MM-DD` format (e.g., `"1990-05-15"`). The `reference_date` is guaranteed to be on or after `birth_date`. Compute the exact age in completed years, months, and days, using calendar month lengths (not 30-day months). Return a dictionary with keys `"years"`, `"months"`, and `"days"`. **Rules for calculation:** - A year is completed when the month and day are >= birth month and day. - After subtracting years, a month is completed when the day of the month (adjusted for end-of-month) is >= birth day. - Use the actual calendar (e.g., February has 28 or 29 days). - For example, from `2000-01-31` to `2000-02-29` is 0 years, 0 months, 29 days (not 1 month). You may use the `datetime` module from the standard library.

Constraints

- Dates are valid Gregorian calendar dates in `YYYY-MM-DD` format. - `reference_date >= birth_date`. - Year range: 1900 to 2100. - Complexity: O(1).

Example

```python
>>> age_years_months_days("1990-05-15", "2024-05-15")
{'years': 34, 'months': 0, 'days': 0}

>>> age_years_months_days("2000-01-31", "2000-02-01")
{'years': 0, 'months': 0, 'days': 1}

>>> age_years_months_days("2000-02-29", "2001-02-28")
{'years': 0, 'months': 11, 'days': 30}
```
10 points ~15 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Parse dates using `datetime.strptime` or `date.fromisoformat`.
First compute years by checking if the (month, day) has already occurred in the reference year.
After years, compute months similarly, then days using calendar month lengths.
Be careful with end-of-month: if birth day is 31 and the current month has fewer days, compare with the last valid day of that month.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.