(
    dt: Optional[datetime], source: BaseRelation, field_name: str
)
If dt has a timezone, return a new datetime that's in UTC. Otherwise,
    assume the datetime is already for UTC and add the timezone.
If dt has a timezone, return a new datetime that's in UTC. Otherwise,
    assume the datetime is already for UTC and add the timezone.
If dt has a timezone return a new datetime that s in UTC . Otherwise assume the datetime is already for UTC and add the timezone .
def _utc(
    dt: Optional[datetime], source: BaseRelation, field_name: str
) -> datetime:
    """If dt has a timezone, return a new datetime that's in UTC. Otherwise,
    assume the datetime is already for UTC and add the timezone.
    """
    if dt is None:
        raise raise_database_error(
            "Expected a non-null value when querying field '{}' of table "
            " {} but received value 'null' instead".format(
                field_name,
                source))

    elif not hasattr(dt, 'tzinfo'):
        raise raise_database_error(
            "Expected a timestamp value when querying field '{}' of table "
            "{} but received value of type '{}' instead".format(
                field_name,
                source,
                type(dt).__name__))

    elif dt.tzinfo:
        return dt.astimezone(pytz.UTC)
    else:
        return dt.replace(tzinfo=pytz.UTC)
def _utc ( dt : Optional [ datetime ] , source : BaseRelation , field_name : str ) -> datetime : if dt is None : raise raise_database_error ( "Expected a non-null value when querying field '{}' of table " " {} but received value 'null' instead" . format ( field_name , source ) ) elif not hasattr ( dt , 'tzinfo' ) : raise raise_database_error ( "Expected a timestamp value when querying field '{}' of table " "{} but received value of type '{}' instead" . format ( field_name , source , type ( dt ) . __name__ ) ) elif dt . tzinfo : return dt . astimezone ( pytz . UTC ) else : return dt . replace ( tzinfo = pytz . UTC )