import time
import calendar


def to_timestamp(dt):
    """
    Converts a datetime object to a timestamp (seconds since epoch).

    :param dt: datetime object (naive or aware)
    :returns: timestamp (seconds since epoch)

    Native datetime objects will be treated as local time.

    .. note::
       Epoch is defined as 00:00:00 UTC on 1 January 1970.  It is *always* UTC.
    """
    if dt.tzinfo is None:
        # Treat naive objects as local time.
        return time.mktime(dt.timetuple()) + dt.microsecond / 1000000.0
    else:
        return calendar.timegm(dt.utctimetuple()) + dt.microsecond / 1000000.0