def to_datetime(value, ctx):
    """
    Tries conversion of any value to a datetime
    """
    if isinstance(value, str):
        temporal = ctx.get_date_parser().auto(value)
        if temporal is not None:
            return to_datetime(temporal, ctx)
    elif type(value) == datetime.date:
        return ctx.timezone.localize(datetime.datetime.combine(value, datetime.time(0, 0)))
    elif isinstance(value, datetime.datetime):
        return value.astimezone(ctx.timezone)

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