def cleaned_date(day, keep_datetime=False):
if not isinstance(day, (date, datetime)):<EOL><INDENT>raise UnsupportedDateType(<EOL>"<STR_LIT>".format(day, type(day)))<EOL><DEDENT>if not keep_datetime:<EOL><INDENT>if hasattr(day, '<STR_LIT:date>') and callable(day.date):<EOL><INDENT>day = day.date()<EOL><DEDENT><DEDENT>return day<EOL>
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.