def timeFormat(time_from, time_to=None, prefix="", infix=None):
    """
    Format the times time_from and optionally time_to, e.g. 10am
    """
    retval = ""
    if time_from != "" and time_from is not None:
        retval += prefix
        retval += dateformat.time_format(time_from, "fA").lower()
    if time_to != "" and time_to is not None:
        to = format(dateformat.time_format(time_to, "fA").lower())
        if infix is not None:
            retval = "{} {} {}".format(retval, infix, to)
        else:
            retval = _("{fromTime} to {toTime}").format(fromTime=retval,
                                                        toTime=to)
    return retval.strip()
Format the times time_from and optionally time_to, e.g. 10am