Update eta.go

This commit is contained in:
Justin 2025-11-28 11:40:51 +01:00 committed by GitHub
parent a122dbe459
commit 09bdbf95c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,10 +21,11 @@ import "time"
// CalculateETA calculates the estimated remaining time based on the
// number of finished task, remaining task, and the time cost for finished task.
func CalculateETA(done, left uint64, elapsed time.Duration) time.Duration {
if done == 0 || elapsed.Milliseconds() == 0 {
ms := elapsed.Milliseconds()
if done == 0 || ms == 0 {
return 0
}
speed := float64(done) / float64(elapsed.Milliseconds())
speed := float64(done) / float64(ms)
return time.Duration(float64(left)/speed) * time.Millisecond
}