def _get_kernel_query(starttime: int, endtime: int, buffer: int):
    """
    Create a HDF5 kernel query based on start and end times.

    This is necessary because hdf5 doesnt accept inverted conditions.
    A slight buffer is applied to the ranges to make sure no edge files
    are excluded.
    """
    t1 = starttime - buffer
    t2 = endtime + buffer
    con = (
        f'(starttime>{t1:d} & starttime<{t2:d}) | ((endtime>{t1:d} & endtime<{t2:d}) | (starttime<{t1:d} & endtime>{t2:d}))'
        )
    return con
