def _time_element_period_length(time_element) -> int:
    """Returns total period length for sorting
    Handles unbounded periods by using 9999 as the period length"""
    total_period_length = time_element.get_total_period_length()
    return total_period_length if total_period_length is not None else 9999