mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
1941 Observed data: Set UTC time spec for parsed QDateTime object
This commit is contained in:
parent
9db96cbb1b
commit
500aaed00b
@ -95,29 +95,37 @@ bool RifColumnBasedUserData::parse(const QString& data)
|
||||
|
||||
startDate = QDateTime::fromString(startDateString, dateFormatString);
|
||||
}
|
||||
else
|
||||
{
|
||||
startDate.setDate(QDate(01, 01, 1970));
|
||||
}
|
||||
|
||||
m_timeSteps.resize(m_timeSteps.size() + 1);
|
||||
|
||||
quint64 scaleFactor = RiaDateTimeTools::secondsFromUnit(ci.unitName);
|
||||
std::vector<time_t>& timeSteps = m_timeSteps.back();
|
||||
|
||||
if (startDate.isValid())
|
||||
QString unit = QString::fromStdString(ci.unitName).trimmed().toUpper();
|
||||
|
||||
if (unit == "DAY" || unit == "DAYS")
|
||||
{
|
||||
for (const auto& timeStepValue : ci.values)
|
||||
{
|
||||
QDateTime dateTime = startDate.addSecs(scaleFactor * timeStepValue);
|
||||
|
||||
QDateTime dateTime = startDate.addDays((int)timeStepValue);
|
||||
dateTime.setTimeSpec(Qt::UTC);
|
||||
timeSteps.push_back(dateTime.toTime_t());
|
||||
}
|
||||
}
|
||||
else
|
||||
else if (unit == "YEAR" || unit == "YEARS")
|
||||
{
|
||||
for (const auto& timeStepValue : ci.values)
|
||||
{
|
||||
timeSteps.push_back(scaleFactor * timeStepValue);
|
||||
QDateTime dateTime = startDate.addYears((int)timeStepValue);
|
||||
dateTime.setTimeSpec(Qt::UTC);
|
||||
timeSteps.push_back(dateTime.toTime_t());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (size_t columIndex = 0; columIndex < m_parser->tables()[tableIndex].size(); columIndex++)
|
||||
{
|
||||
const ColumnInfo& ci = m_parser->tables()[tableIndex][columIndex];
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RifColumnBasedAsciiParser.h"
|
||||
#include "RifColumnBasedUserData.h"
|
||||
#include "RifColumnBasedUserDataParser.h"
|
||||
#include "RifKeywordVectorParser.h"
|
||||
#include "RifRsmspecParserTools.h"
|
||||
@ -539,5 +540,71 @@ TEST(RifKeywordBasedRsmspecParserTest, TestShutins)
|
||||
|
||||
EXPECT_EQ("OP-1", tables.at(0).at(2).summaryAddress.wellName());
|
||||
EXPECT_NE("OP-1", tables.at(0).at(1).summaryAddress.wellName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RifKeywordBasedRsmspecParserTest, TestTimeSteps)
|
||||
{
|
||||
QString data;
|
||||
QTextStream out(&data);
|
||||
|
||||
out << "-- Created running the command shutin_pressures\n";
|
||||
out << "\n";
|
||||
out << "PAGE 1\n";
|
||||
out << "ORIGIN OP-1_WBP9L\n";
|
||||
out << "STARTDATE 01 01 2004 -- DD MM YYYY\n";
|
||||
out << "\n";
|
||||
out << "TIME YEARX WBP9L\n";
|
||||
out << "DAYS YEARS BARSA\n";
|
||||
out << "1 1 1\n";
|
||||
out << " OP-1\n";
|
||||
out << "\n";
|
||||
out << "\n";
|
||||
out << "3043 2014.32 52.5 -- Extrapolated\n";
|
||||
out << "3046 2014.32 208.8 -- Measured\n";
|
||||
out << "3070 2014.39 197.6 -- Measured\n";
|
||||
out << "3081 2014.42 200.3 -- Measured\n";
|
||||
out << "3128 2014.55 203.3 -- Measured\n";
|
||||
out << "3141 2014.59 198.0 -- Measured\n";
|
||||
out << "3196 2014.73 197.2 -- Measured\n";
|
||||
out << "3222 2014.81 196.9 -- Extrapolated\n";
|
||||
out << "3225 2014.82 199.6 -- Extrapolated\n";
|
||||
out << "3226 2014.82 200.0 -- Extrapolated\n";
|
||||
out << "3247 2014.87 201.8 -- Extrapolated\n";
|
||||
out << "3282 2014.97 51.7 -- Extrapolated\n";
|
||||
out << "3282 2014.97 201.6 -- Measured\n";
|
||||
out << "3304 2015.03 206.1 -- Extrapolated\n";
|
||||
out << "3324 2015.09 170.2 -- Measured\n";
|
||||
out << "3359 2015.18 207.0 -- Extrapolated\n";
|
||||
out << "3481 2015.52 151.0 -- Measured\n";
|
||||
out << "3493 2015.55 219.0 -- Measured\n";
|
||||
out << "\n";
|
||||
|
||||
std::string quantityName = "WBP9L";
|
||||
std::vector< std::string > headerColumn;
|
||||
headerColumn.push_back("OP-1");
|
||||
|
||||
RifEclipseSummaryAddress address = RifRsmspecParserTools::makeAndFillAddress(quantityName, headerColumn);
|
||||
|
||||
RifColumnBasedUserData columnBasedUserdata;
|
||||
|
||||
columnBasedUserdata.parse(data);
|
||||
std::vector<time_t> timeSteps = columnBasedUserdata.timeSteps(address);
|
||||
|
||||
QDateTime startDate = QDateTime::fromString("01012004", "ddMMyyyy");
|
||||
startDate.setTimeSpec(Qt::UTC);
|
||||
|
||||
QDateTime qDay1 = startDate.addDays(3043);
|
||||
time_t day1 = qDay1.toTime_t();
|
||||
|
||||
ASSERT_EQ(18, timeSteps.size());
|
||||
|
||||
EXPECT_EQ("Tue May 1 00:00:00 2012\n", (std::string)asctime(gmtime(&day1)));
|
||||
EXPECT_EQ("Tue May 1 00:00:00 2012\n", (std::string)asctime(gmtime(&timeSteps[0])));
|
||||
|
||||
EXPECT_EQ(day1, timeSteps[0]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user