simplify rolling window code, and make tests run faster (#343)

This commit is contained in:
Kevin Wan
2021-01-03 20:47:29 +08:00
committed by GitHub
parent 2ee95f8981
commit 771371e051
2 changed files with 28 additions and 27 deletions

View File

@@ -17,7 +17,7 @@ type (
interval time.Duration
offset int
ignoreCurrent bool
lastTime time.Duration
lastTime time.Duration // start time of the last bucket
}
)
@@ -96,7 +96,7 @@ func (rw *RollingWindow) updateOffset() {
}
rw.offset = (offset + span) % rw.size
rw.lastTime = time.Duration(int(rw.lastTime) + int(rw.interval)*span)
rw.lastTime = rw.lastTime + rw.interval*time.Duration(span)
}
type Bucket struct {