From a25f58731e29030d436bd23bd2bc2469b67e9061 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Mon, 10 Feb 2020 14:40:21 +0100 Subject: [PATCH] Fix of d81f7d84652c07806bc76d75dcfa4dbbc8904d05 (SlicedInfo: Removed secondes from estimated times): GCodeTimeEstimator::_get_time_dhm() shall round to minutes, old code rounded down to minutes, new code rounds to 1/2. --- src/libslic3r/GCodeTimeEstimator.cpp | 29 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/libslic3r/GCodeTimeEstimator.cpp b/src/libslic3r/GCodeTimeEstimator.cpp index 17f826c57..3ef325aef 100644 --- a/src/libslic3r/GCodeTimeEstimator.cpp +++ b/src/libslic3r/GCodeTimeEstimator.cpp @@ -1623,22 +1623,23 @@ namespace Slic3r { std::string GCodeTimeEstimator::_get_time_dhm(float time_in_secs) { - int days = (int)(time_in_secs / 86400.0f); - time_in_secs -= (float)days * 86400.0f; - int hours = (int)(time_in_secs / 3600.0f); - time_in_secs -= (float)hours * 3600.0f; - int minutes = (int)(time_in_secs / 60.0f); - time_in_secs -= (float)minutes * 60.0f; - char buffer[64]; - if (days > 0) - ::sprintf(buffer, "%dd %dh %dm", days, hours, minutes); - else if (hours > 0) - ::sprintf(buffer, "%dh %dm", hours, minutes); - else if (minutes > 0) - ::sprintf(buffer, "%dm", minutes); - else + + int minutes = std::round(time_in_secs / 60.); + if (minutes <= 0) { ::sprintf(buffer, "%ds", (int)time_in_secs); + } else { + int days = minutes / 1440; + minutes -= days * 1440; + int hours = minutes / 60; + minutes -= hours * 60; + if (days > 0) + ::sprintf(buffer, "%dd %dh %dm", days, hours, minutes); + else if (hours > 0) + ::sprintf(buffer, "%dh %dm", hours, minutes); + else + ::sprintf(buffer, "%dm", minutes); + } return buffer; }