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