             # newer than latest snapshot),
             # then clear cache, since can't build on it
             for x in v
-                if @_cache.last_snapshot - 0 <= x.time - 0 <= @_cache.patch.time - 0
+                if x.time - 0 <= @_cache.time - 0
                     delete @_cache
                     break
         # this is O(n*log(n)) where n is the length of @_patches and patches;

                if time? and x.time > time
                    break
                value = apply_patch(x.patch, value)[0]

        if not time? and x?   # x? = there was at least one new patch
            @_cache = {patch:x, value:value, start:@_patches.length, last_snapshot:last_snapshot}

        return value


    value: (time) =>
        if time? and not misc.is_date(time)
            throw Error("time must be a date")
        cache_time = 0
        if not time? and @_cache?
            value = @_cache.value
            for x in @_patches.slice(@_cache.start, @_patches.length)
                value = apply_patch(x.patch, value)[0]
                cache_time = x.patch.time
        else
            # find the newest snapshot at a time that is <=time
            value = '' # default in case no snapshots
            start = 0
            if @_patches.length > 0
                for i in [@_patches.length-1 .. 0]
                    if (not time? or @_patches[i].time - time <= 0) and @_patches[i].snapshot?
                        value = @_patches[i].snapshot
                        start = i + 1
                        break
            for i in [start...@_patches.length]
