Convert a Python timestamp to an 8 byte KNX time and date object

def datetime_to_knx(datetimeval, clock_synced_external=1):
    """Convert a Python timestamp to an 8 byte KNX time and date object"""

    res = [0, 0, 0, 0, 0, 0, 0, 0]
    year = datetimeval.year
    if (year < 1900) or (year > 2155):
        raise KNXException("Only years between 1900 and 2155 supported")
    res[0] = year - 1900
    res[1] = datetimeval.month
    res[2] = datetimeval.day
    res[3] = (datetimeval.isoweekday() << 5) + datetimeval.hour
    res[4] = datetimeval.minute
    res[5] = datetimeval.second
    if datetimeval.isoweekday() < 6:
        is_working_day = 1
    else:
        is_working_day = 0

    # DST starts last Sunday in March
    date1 = datetime(year, 4, 1)
    dston = date1 - timedelta(days=date1.weekday() + 1)
    # ends last Sunday in October
    date2 = datetime(year, 11, 1)
    dstoff = date2 - timedelta(days=date2.weekday() + 1)
    if dston <= datetimeval.replace(tzinfo=None) < dstoff:
        dst = 1
    else:
        dst = 0

    res[6] = (is_working_day << 6) + (1 << 5) + dst
    if clock_synced_external:
        res[7] = 128
    else:
        res[7] = 0

    return res