Removing old TimeIntervalCollectionProperty data

Hi, I load IntervalCollection data dynamically, so after a while it starts to build up. I am wondering how to clear intervals before a certain time.

I have tried:
        var priorTimeInterval = new Cesium.TimeInterval({
            start : Cesium.JulianDate.fromIso8601('1980-08-01T00:00:00Z'),
            stop : time,
            isStartTimeIncluded : true,
            iSStopTimeIncluded : true,
            data : null

I figured that this would leave empty space before the specified time value, but it seems to remove interval data after the specified time as well.

I also tried iterating through the intervals in the collection and using something like:
        for (var i = 0; i < intervals.length; i++) {
            if ([i].stop, time) < 0){
                if (collection.intervals.removeInterval(intervals[i])){

That seemed better (didn't remove all of the descriptions), but it still removed some of them after the specified time if they didn't change for a while. Should I also be taking into account isStopIncluded or isStartIncluded?

Thank you.

Your first attempt looks correct (though you don’t need the ‘data :null’, just leave it out completely). Can you come up with a complete example that shows the problem? Preferably something that works in Sandcastle. I can’t reproduce the problem you are seeing.

I've reproduced it (at least on Chrome 45 and Firefox 40).

The below code creates alternating red/green outlines via a time interval. There is a lot of weird behaviour.

1. When the page first loads the outline is white. If you pause immediately and drag the slider to 08:00:19 and back to 08:00:00 it will change the outline to green.

2. If you drag the slider forwards past 08:00:20 again and back to 08:00:00 it'll change the outline to red or green (seems to vary, oddly).

3. If you uncomment the "//seconds = 21;" line the interval appears to be completely broken and the outline just displays as black.

My question is:
How do I only delete all interval data before (and including) 08:00:20?
I am loading live data and they just build up until the browser runs out of memory. If I try to remove them, this happens.

Paste the following into sandcastle:

var viewer = new Cesium.Viewer('cesiumContainer');
var entities = viewer.entities;

//Set bounds of our simulation time
var start = Cesium.JulianDate.fromDate(new Date(2015, 2, 25, 16, 0, 0));
var stop = Cesium.JulianDate.addSeconds(start, 360, new Cesium.JulianDate());

//Make sure viewer is at the desired time.
viewer.clock.startTime = start.clone();
viewer.clock.stopTime = stop.clone();
viewer.clock.currentTime = start.clone();

//Set timeline to simulation bounds
viewer.timeline.zoomTo(start, stop);

// Create alternating colours
function computeColors() {
    var colorIntervalCollection = new Cesium.TimeIntervalCollectionProperty();
    var increment = 80;
    var iteration = 0;
    for (var i = -60; i <= 360; i += increment) {
        iteration += 1;
        var time = Cesium.JulianDate.addSeconds(start, i, new Cesium.JulianDate());
        var nextTime = Cesium.JulianDate.addSeconds(time, increment, new Cesium.JulianDate());
        var color = Cesium.Color.RED;
        if (iteration % 2){
            color = Cesium.Color.GREEN;
        colorIntervalCollection.intervals.addInterval(new Cesium.TimeInterval({
            start: time,
            stop: nextTime,
            isStartIncluded: true,
            isStopIncluded: true,
            data: color
    return colorIntervalCollection;

var colorInterval = computeColors();

// Ages before the first interval
var removeStart = Cesium.JulianDate.fromDate(new Date(2000, 1, 1, 0, 0, 0));

// Relevant part:
// This doesn't appear to break anything. Dragging the slider before 08:00:19 shows the color red
var seconds = 19;
// Uncomment this to remove the red interval and show green instead before 08:00:20
//seconds = 20;
// Uncomment this to break everything
//seconds = 21;

var removeEnd = Cesium.JulianDate.fromDate(new Date(2015, 2, 25, 16, 0, seconds));

// Remove interval
colorInterval.intervals.removeInterval(new Cesium.TimeInterval({
    start: removeStart,
    stop: removeEnd,
    isStartIncluded: true,
    isStopIncluded: true

// Add entity to viewer entitycollection
var entity = entities.add({
    rectangle : {
        coordinates : Cesium.Rectangle.fromDegrees(-92.0, 20.0, -86.0, 27.0),
        outline : true,
        outlineColor : colorInterval,
        outlineWidth : 12,
        material: Cesium.Color.BLUE