from datetime import datetime


def get_datetime_with_offset(date, offset=300):

    """ Returns a forward or backward date given a date and an offset
        time in seconds

        :param offset: offset interval in seconds (default: 300s).
                       The offset can be positive or negative
        :param offset: the reference datetime
        :return datetime: the anterior datetime
        :raises Exception: Invalid parameters
    """

    if (type(offset) is int) and (type(date) is datetime):

        ref_ts = datetime.timestamp(date)
        offset_ts = ref_ts + offset

        return datetime.fromtimestamp(offset_ts)

    else:
        raise Exception("Invalid parameters.")