DateTimeUtcLess🔗

Type: Transpilable verification function
Check that the date-time that is before other.

We compare the years as integers, and the rest of the texts part by part as strings, since the fraction of a second can be arbitrarily long.

We do not compare the years with more than 15 digits, as they do not safely fit into an integer. Such years are valid in xs:dateTime, but not realistic.

The end of a day, 24:00:00, is the same instant as the start of the next day, see the note at https://www.w3.org/TR/xmlschema-2/#dateTime.

that🔗
Date-time which is expected to come first
other🔗
Date-time which is expected to come later
Return🔗
True if that is before other, False if not, and None if either of them is not a valid xs:dateTime in UTC, or if either of their years has more than 15 digits

Code

if not is_xs_date_time_UTC(that) or not is_xs_date_time_UTC(other):
    return None

# NOTE (mristin):
# We start searching from the second character so that we skip the minus
# of a year B.C.
that_month_start = that.find("-", 1) + 1
other_month_start = other.find("-", 1) + 1

that_year_text = that[: that_month_start - 1]
other_year_text = other[: other_month_start - 1]

if len(that_year_text.lstrip("-")) > 15 or len(other_year_text.lstrip("-")) > 15:
    return None

# NOTE (mristin):
# The years B.C. are negative, so they are ordered as the integers, even
# though there is no year zero in between.
that_year = int(that_year_text)
other_year = int(other_year_text)

# NOTE (mristin):
# The month, the day, the hours, the minutes and the whole seconds, given as
# ``MM-DDTHH:MM:SS``, are of fixed width, so they are ordered as the texts.
that_rest = that[that_month_start : that_month_start + 14]
other_rest = other[other_month_start : other_month_start + 14]

that_fraction = _fraction_of_date_time_UTC(that).rstrip("0")
other_fraction = _fraction_of_date_time_UTC(other).rstrip("0")

less = False

if that_year != other_year:
    less = that_year < other_year

elif that_rest != other_rest:
    less = that_rest < other_rest

else:
    # NOTE (mristin):
    # The fractions are stripped of the trailing zeros, so they are ordered
    # as the texts.
    less = that_fraction < other_fraction

# NOTE (mristin):
# The end of a day sorts after all the other times of the same day, and before
# all the times of the later days, which is correct except for the start of
# the next day, as the two are the same instant. If :paramref:`other` is
# the end of a day instead, it sorts correctly, as the start of the next day
# comes after all the times of that day.
if (
    less
    and that[that_month_start + 6 : that_month_start + 8] == "24"
    and other[other_month_start + 6 : other_month_start + 14] == "00:00:00"
    and other_fraction == ""
):
    return not _is_next_day(that, other)

return less