IsNextDay🔗

Type: Transpilable verification function
Check that the date of nextText is the day after the date of text.
Both text and nextText are expected to start with a valid date matching the pattern -?YYYY-MM-DD, where the year can have more than four digits, but has to fit into an integer. Whatever follows the date, such as the time or the time zone, is ignored.
text🔗
Text starting with the date to be incremented
next_text🔗
Text starting with the date expected to follow
Return🔗
True if the date of nextText follows the date of text

Code

month_start = text.find("-", 1) + 1
next_month_start = next_text.find("-", 1) + 1

year_text = text[: month_start - 1]

year = int(year_text)
month = int(text[month_start : month_start + 2])
day = int(text[month_start + 3 : month_start + 5])

next_year = int(next_text[: next_month_start - 1])
next_month = int(next_text[next_month_start : next_month_start + 2])
next_day = int(next_text[next_month_start + 3 : next_month_start + 5])

if _is_day_of_month_valid(_is_leap_year(year_text), month, day + 1):
    return year == next_year and month == next_month and day + 1 == next_day

if next_day != 1:
    return False

if month < 12:
    return year == next_year and month + 1 == next_month

# NOTE (mristin):
# There is no year zero, see the note at
# https://www.w3.org/TR/xmlschema-2/#dateTime, so the year 1 B.C., ``-0001``,
# is followed by the year 1, ``0001``.
return next_month == 1 and (
    next_year == year + 1 or (year == -1 and next_year == 1)
)