from datetime import datetime


def rstime_to_datetime(rstime):
    """
    Parses a Runstatus API timestamp and returns the corresponding datetime object.
    """

    try:
        return datetime.strptime(rstime, "%Y-%m-%dT%H:%M:%S.%fZ")
    except ValueError:
        return datetime.strptime(rstime, "%Y-%m-%dT%H:%M:%SZ")