diff --git a/solver/processing.go b/solver/processing.go index edfe0e8..aea83fc 100644 --- a/solver/processing.go +++ b/solver/processing.go @@ -146,7 +146,13 @@ func (solver *Solver) tracker() { if rate_diff == 0 { est_fin = "N/A" } else { - est_fin = solver.secondsToHuman((solver.iter - solver.counter.Load()) / rate_avg) + duration_int := (solver.iter - solver.counter.Load()) / rate_avg + duration_string := strconv.Itoa(int(duration_int)) + "s" + est, err := time.ParseDuration(duration_string) + if err != nil { + est_fin = "parse error" + } + est_fin = est.String() } // Printing the progress diff --git a/solver/timers.go b/solver/timers.go index ad35d7b..6ed2952 100644 --- a/solver/timers.go +++ b/solver/timers.go @@ -2,8 +2,6 @@ package solver import ( "log" - "math" - "strconv" "time" ) @@ -11,46 +9,3 @@ func (solver *Solver) timeTrack(start time.Time, msg string) { elapsed := time.Since(start) log.Printf("%s (%s)", msg, elapsed) } - -// Stolen from https://socketloop.com/tutorials/golang-convert-seconds-to-human-readable-time-format-example -func (solver *Solver) plural(count int, singular string) (result string) { - if (count == 1) || (count == 0) { - result = strconv.Itoa(count) + " " + singular + " " - } else { - result = strconv.Itoa(count) + " " + singular + "s " - } - return -} - -func (solver *Solver) secondsToHuman(input int64) (result string) { - years := math.Floor(float64(input) / 60 / 60 / 24 / 7 / 30 / 12) - seconds := input % (60 * 60 * 24 * 7 * 30 * 12) - months := math.Floor(float64(seconds) / 60 / 60 / 24 / 7 / 30) - seconds = input % (60 * 60 * 24 * 7 * 30) - weeks := math.Floor(float64(seconds) / 60 / 60 / 24 / 7) - seconds = input % (60 * 60 * 24 * 7) - days := math.Floor(float64(seconds) / 60 / 60 / 24) - seconds = input % (60 * 60 * 24) - hours := math.Floor(float64(seconds) / 60 / 60) - seconds = input % (60 * 60) - minutes := math.Floor(float64(seconds) / 60) - seconds = input % 60 - - if years > 0 { - result = solver.plural(int(years), "year") + solver.plural(int(months), "month") + solver.plural(int(weeks), "week") + solver.plural(int(days), "day") + solver.plural(int(hours), "hour") + solver.plural(int(minutes), "minute") + solver.plural(int(seconds), "second") - } else if months > 0 { - result = solver.plural(int(months), "month") + solver.plural(int(weeks), "week") + solver.plural(int(days), "day") + solver.plural(int(hours), "hour") + solver.plural(int(minutes), "minute") + solver.plural(int(seconds), "second") - } else if weeks > 0 { - result = solver.plural(int(weeks), "week") + solver.plural(int(days), "day") + solver.plural(int(hours), "hour") + solver.plural(int(minutes), "minute") + solver.plural(int(seconds), "second") - } else if days > 0 { - result = solver.plural(int(days), "day") + solver.plural(int(hours), "hour") + solver.plural(int(minutes), "minute") + solver.plural(int(seconds), "second") - } else if hours > 0 { - result = solver.plural(int(hours), "hour") + solver.plural(int(minutes), "minute") + solver.plural(int(seconds), "second") - } else if minutes > 0 { - result = solver.plural(int(minutes), "minute") + solver.plural(int(seconds), "second") - } else { - result = solver.plural(int(seconds), "second") - } - - return -}