def to_time(value, ctx):
    """
    Tries conversion of any value to a time
    """
    if isinstance(value, str):
        time = ctx.get_date_parser().time(value)
        if time is not None:
            return time
    elif isinstance(value, datetime.time):
        return value
    elif isinstance(value, datetime.datetime):
        return value.astimezone(ctx.timezone).time()

    raise EvaluationError("Can't convert '%s' to a time" % str(value))
def to_time ( value , ctx ) : if isinstance ( value , str ) : time = ctx . get_date_parser ( ) . time ( value ) if time is not None : return time elif isinstance ( value , datetime . time ) : return value elif isinstance ( value , datetime . datetime ) : return value . astimezone ( ctx . timezone ) . time ( ) raise EvaluationError ( "Can't convert '%s' to a time" % str ( value ) )
Tries conversion of any value to a time