import _datetime


def datetime_to_datetime(d):
    """Return the passed datetime as a datetime that is clean
    and usable by Acquire. This will move the datetime to UTC,
    adding the timezone if this is missing

    Args:
         d (datetime): datetime to convert to UTC
    Returns:
         datetime: UTC datetime useable by Acquire

    """
    if not isinstance(d, _datetime.datetime):
        raise TypeError("The passed object '%s' is not a valid datetime" % str(d))

    if d.tzinfo is None:
        return d.replace(tzinfo=_datetime.timezone.utc)
    else:
        return d.astimezone(_datetime.timezone.utc)