Check eta value for math.IsInf or math.IsNaN
Vladimir Bauer
8 years ago
| 1 | 1 | |
| 2 | 2 | import ( |
| 3 | 3 | "fmt" |
| 4 | "math" | |
| 4 | 5 | "time" |
| 5 | 6 | |
| 6 | 7 | "github.com/VividCortex/ewma" |
| 59 | 60 | return s.onComplete.wc.FormatMsg(s.onComplete.msg, widthAccumulator, widthDistributor) |
| 60 | 61 | } |
| 61 | 62 | |
| 62 | var str string | |
| 63 | timeRemaining := time.Duration(st.Total-st.Current) * time.Duration(round(s.mAverage.Value())) | |
| 63 | v := round(s.mAverage.Value()) | |
| 64 | if math.IsInf(v, 0) || math.IsNaN(v) { | |
| 65 | v = .0 | |
| 66 | } | |
| 67 | timeRemaining := time.Duration(st.Total-st.Current) * time.Duration(v) | |
| 64 | 68 | hours := int64((timeRemaining / time.Hour) % 60) |
| 65 | 69 | minutes := int64((timeRemaining / time.Minute) % 60) |
| 66 | 70 | seconds := int64((timeRemaining / time.Second) % 60) |
| 67 | 71 | |
| 72 | var str string | |
| 68 | 73 | switch s.style { |
| 69 | 74 | case ET_STYLE_GO: |
| 70 | 75 | str = fmt.Sprint(time.Duration(timeRemaining.Seconds()) * time.Second) |