From a4b451785dd30a4299a0f2bedbccf7669ca68e93 Mon Sep 17 00:00:00 2001 From: Moritz Date: Mon, 25 Apr 2022 11:05:24 +0200 Subject: [PATCH] Timing: Fixed issues in DurationFromString Previously this function was implemented wrongly, which caused problems with the max_walltime of simulations. --- core/src/utility/Timing.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/core/src/utility/Timing.cpp b/core/src/utility/Timing.cpp index fc873fe8f..3f384bb9f 100644 --- a/core/src/utility/Timing.cpp +++ b/core/src/utility/Timing.cpp @@ -77,29 +77,37 @@ scalar HoursPassed( duration dt ) duration DurationFromString( const std::string & dt ) { - std::uint8_t hours = 0, minutes = 0; - std::uint64_t seconds = 0; + std::int32_t hours = 0, minutes = 0; + std::int64_t seconds = 0; std::istringstream iss( dt ); std::string token = ""; // Hours if( std::getline( iss, token, ':' ) ) + { if( !token.empty() ) - iss >> hours; + hours = std::stoi( token ); + } + // Minutes if( std::getline( iss, token, ':' ) ) + { if( !token.empty() ) - iss >> minutes; + minutes = std::stoi( token ); + } + // Seconds if( std::getline( iss, token, ':' ) ) + { if( !token.empty() ) - iss >> seconds; + seconds = std::stol( token ); + } // Convert to std::chrono::seconds seconds += 60 * minutes + 60 * 60 * hours; - std::chrono::seconds chrono_seconds( seconds ); + std::chrono::seconds chrono_seconds( seconds ); // Return duration return duration( chrono_seconds ); }