code: def cleaned_date(day, keep_datetime=False):
      
      if not isinstance(day, (date, datetime)):
          raise UnsupportedDateType(
              "`{}` is of unsupported type ({})".format(day, type(day)))
      if not keep_datetime:
          if hasattr(day, 'date') and callable(day.date):
              day = day.date()
      return day
docs: Return a "clean" date type.
  
      * keep a `date` unchanged
      * convert a datetime into a date,
      * convert any "duck date" type into a date using its `date()` method.