import time


def to_epoch(datetime_obj, astype=int):
    """Convert datetime.datetime into epoch seconds

    Currently assumes input datetime is expressed in localtime.  Does not handle
    timezones very well.  Once Python2 support is dropped from pytokio, this will
    be replaced by Python3's datetime.datetime.timestamp() method.

    Args:
        datetime_obj (datetime.datetime): Datetime to convert to seconds-since-epoch
        astype: Whether you want the resulting timestamp as an int or float

    Returns:
        int or float: Seconds since epoch
    """

    if astype == float:
        return time.mktime(datetime_obj.timetuple()) + datetime_obj.microsecond / 1e6
    return astype(time.mktime(datetime_obj.timetuple()))