def _update_impl(self, vevent, href, calendar):
        """insert `vevent` into the database

        expand `vevent`'s reccurence rules (if needed) and insert all instance
        in the respective tables
        than insert non-reccuring and original recurring (those with an RRULE
        property) events into table `events`
        """
        # TODO FIXME this function is a steaming pile of shit
        rec_id = vevent.get(RECURRENCE_ID)
        if rec_id is None:
            rrange = None
        else:
            rrange = rec_id.params.get('RANGE')

        # testing on datetime.date won't work as datetime is a child of date
        if not isinstance(vevent['DTSTART'].dt, datetime):
            dtype = DATE
        else:
            dtype = DATETIME
        if (vevent['DTSTART'].params in 'TZID' and dtype == DATETIME) or \
                getattr(vevent['DTSTART'].dt, 'tzinfo', None):
            recs_table = 'recs_loc'
        else:
            recs_table = 'recs_float'

        thisandfuture = (rrange == THISANDFUTURE)
        if thisandfuture:
            start_shift, duration = calc_shift_deltas(vevent)
            start_shift = start_shift.days * 3600 * 24 + start_shift.seconds
            duration = duration.days * 3600 * 24 + duration.seconds

        dtstartend = aux.expand(vevent, href)
        if not dtstartend:
            # Does this event even have dates? Technically it is possible for
            # events to be empty/non-existent by deleting all their recurrences
            # through EXDATE.
            return

        for dtstart, dtend in dtstartend:
            if dtype == DATE:
                dbstart = aux.to_unix_time(dtstart)
                dbend = aux.to_unix_time(dtend)
                if rec_id is not None:
                    rec_inst = aux.to_unix_time(rec_id.dt)
                    ref = rec_inst
                else:
                    rec_inst = dbstart
                    ref = PROTO
            else:
                dbstart = aux.to_unix_time(dtstart)
                dbend = aux.to_unix_time(dtend)

                if rec_id is not None:
                    ref = rec_inst = str(aux.to_unix_time(rec_id.dt))
                else:
                    rec_inst = dbstart
                    ref = PROTO

            if thisandfuture:
                recs_sql_s = (
                    'UPDATE {0} SET dtstart = rec_inst + ?, dtend = rec_inst + ?, ref = ? '
                    'WHERE rec_inst >= ? AND href = ? AND calendar = ?;'.format(recs_table))
                stuple = (start_shift, start_shift + duration, ref, rec_inst, href, calendar)
            else:
                recs_sql_s = (
                    'INSERT OR REPLACE INTO {0} '
                    '(dtstart, dtend, href, ref, dtype, rec_inst, calendar)'
                    'VALUES (?, ?, ?, ?, ?, ?, ?);'.format(recs_table))
                stuple = (dbstart, dbend, href, ref, dtype, rec_inst, calendar)
            self.sql_ex(recs_sql_s, stuple)
            # end of loop
dataset/ETHPy150Open pimutils/khal/khal/khalendar/backend.py/SQLiteDb._update_impl/swapped operands of `in`