no divide by zero
This commit is contained in:
parent
7ea905871a
commit
4d677ee389
1 changed files with 6 additions and 1 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue