IsDayOfMonthValid🔗

Type: Transpilable verification function
Check that the day exists in the month.
is_leap_year🔗
True if February has 29 days
month🔗
Month of the year, starting with 1
day🔗
Day of the month, starting with 1
Return🔗
True if the day exists in the month

Code

if month < 1 or month > 12 or day < 1:
    return False

if month == 2:
    if is_leap_year:
        return day <= 29

    return day <= 28

if month == 4 or month == 6 or month == 9 or month == 11:
    return day <= 30

return day <= 31