Skip to content

Commit

Permalink
Timing: Fixed issues in DurationFromString
Browse files Browse the repository at this point in the history
Previously this function was implemented wrongly, which caused problems with the max_walltime of simulations.
  • Loading branch information
Moritz committed Apr 25, 2022
1 parent 735f3e5 commit a4b4517
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions core/src/utility/Timing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,37 @@ scalar HoursPassed( duration<scalar> dt )

duration<scalar> 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<scalar>( chrono_seconds );
}
Expand Down

0 comments on commit a4b4517

Please sign in to comment.