Skip to content

Commit

Permalink
fix time unit for analysis operators
Browse files Browse the repository at this point in the history
  • Loading branch information
janosimas committed Nov 28, 2017
1 parent 51a7162 commit 76fe06d
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/terrama2/core/utility/TimeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,14 @@ double terrama2::core::TimeUtils::convertTimeString(const std::string& time, std
throw terrama2::InitializationException() << terrama2::ErrorDescription(msg);
}

bool isNegative = false;
if(timeStr.front() == '-')
{
isNegative = true;
timeStr.erase(0, 1);
}

// split the input time string in numeric value and unit
std::string numberStr;
std::string unitStr;
std::partition_copy(std::begin(timeStr),
std::end(timeStr),
std::back_inserter(numberStr),
std::back_inserter(unitStr),
[](const char& ch) {return std::isdigit(ch);} );
std::back_inserter(numberStr),
[](const char& ch) {return std::isalpha(ch);} );

// if no unit was given, use defaultUnit
if(unitStr.empty()) unitStr = defaultUnit;
Expand Down Expand Up @@ -203,18 +196,15 @@ double terrama2::core::TimeUtils::convertTimeString(const std::string& time, std
}
else
{
QString msg(QObject::tr("Could not find any known unit of measure in the given string: %1.").arg(QString::fromStdString(time)));
QString msg(QObject::tr("Could not find any known unit of measure in the given string: %1.").arg(QString::fromStdString(timeStr)));
TERRAMA2_LOG_ERROR() << msg;
throw terrama2::InvalidArgumentException() << terrama2::ErrorDescription(msg);
}

if(unitName != "SECOND")
result = unitsManager.getConversion("SECOND", unitName) * result;

if(isNegative)
return -result;
else
return result;
return result;
}


Expand Down

0 comments on commit 76fe06d

Please sign in to comment.