Write is_valid_date(s) that returns True if s is a real calendar date written as YYYY-MM-DD:
- exactly 10 characters: four digits,
-, two digits,-, two digits - year between
0001and9999 - month between
01and12 - day between
01and the number of days in that month; February has 29 days in a leap year (divisible by 4, except centuries unless divisible by 400)
Examples
Input: s = "2024-02-29"
Output: True
Input: s = "2023-02-29"
Output: False
Input: s = "1999-12-31"
Output: True
Constraints
0 <= len(s) <= 20, printable ASCII- Do not use the
datetimemodule
Goals
- Check a fixed-width format position by position
- Convert validated digit groups to numbers
- Apply the leap-year rule to February