import time
from datetime import datetime


def transitmaster_time(string_or_time):
    """
    Converter from a time "HHMMp" to a `datetime.time`.
    """
    if isinstance(string_or_time, time):
        return string_or_time

    return datetime.strptime(
        string_or_time.strip().upper().replace("X", "A") + "M", "%I%M%p"
    ).time()