diff --git a/modules/battery.go b/modules/battery.go index c3d491a8a33197baa4902a8ff1b458c929871be0..b3c249a396361d91d8e82873aa2313bd6615818f 100644 --- a/modules/battery.go +++ b/modules/battery.go @@ -103,9 +103,13 @@ func (b *BatteryMod) Render() string { delta := now.Sub(b.battStats[0].point) if delta >= (60 * time.Second) { discharge := math.Abs(batt.Current - b.battStats[0].charge) - timeLeft := time.Duration(batt.Current/discharge) * delta - left = fmt.Sprintf("%dh%dm", int64(timeLeft.Hours()), int64(timeLeft.Minutes())) - b.battStats = b.battStats[1:] + if discharge > 0 { + timeLeft := time.Duration(batt.Current/discharge) * delta + left = fmt.Sprintf("%dh%dm", int64(timeLeft.Hours()), int64(timeLeft.Minutes()-(timeLeft.Hours()*60))) + b.battStats = b.battStats[1:] + } else { + left = "0h0m" + } } } b.battStats = append(b.battStats, battTS{