def to_date(value, ctx):
    """
    Tries conversion of any value to a date
    """
    if isinstance(value, str):
        temporal = ctx.get_date_parser().auto(value)
        if temporal is not None:
            return to_date(temporal, ctx)
    elif type(value) == datetime.date:
        return value
    elif isinstance(value, datetime.datetime):
        return value.date()  # discard time

    raise EvaluationError("Can't convert '%s' to a date" % str(value))
Tries conversion of any value to a date