Is there some possible optimization to be made here by bucketing seconds and dropping buckets wholesale rather than having to peel off items until you find the start of the window?
You'd end up quantizing the window, but.. dunno, just spitballing here.