Skip to content

Commit

Permalink
no divide by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyng committed Nov 17, 2023
1 parent 7ea9058 commit 4d677ee
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion progress/bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ func (b *Bar) percent() float64 {
}

func (b *Bar) rate() float64 {
return (float64(b.currentValue) - float64(b.initialValue)) / b.elapsed().Seconds()
elapsed := b.elapsed()
if elapsed.Seconds() > 0 {
return (float64(b.currentValue) - float64(b.initialValue)) / elapsed.Seconds()
}

return 0
}

func (b *Bar) elapsed() time.Duration {
Expand Down

0 comments on commit 4d677ee

Please sign in to comment.