mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
DateStringParser. Handle month-first when date is bigger than 12
This commit is contained in:
@@ -46,7 +46,8 @@ QDateTime RiaDateStringParser::parseDateString(const QString& dateString)
|
||||
std::string s = dateString.toStdString();
|
||||
bool parsedOk =
|
||||
tryParseYearFirst(s, year, month, day) ||
|
||||
tryParseDayFirst(s, year, month, day);
|
||||
tryParseDayFirst(s, year, month, day) ||
|
||||
tryParseMonthFirst(s, year, month, day);
|
||||
|
||||
QDateTime dt;
|
||||
dt.setTimeSpec(RiaQDateTimeTools::currentTimeSpec());
|
||||
@@ -106,6 +107,23 @@ bool RiaDateStringParser::tryParseDayFirst(const std::string& s, int& year, int&
|
||||
return tryParseYear(sYear, year) && tryParseMonth(sMonth, month) && tryParseDay(sDay, day);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RiaDateStringParser::tryParseMonthFirst(const std::string& s, int& year, int& month, int& day)
|
||||
{
|
||||
auto firstSep = s.find_first_of(" -_.");
|
||||
auto lastSep = s.find_first_of(" -_.", firstSep + 1);
|
||||
|
||||
if (firstSep == std::string::npos || lastSep == std::string::npos) return false;
|
||||
|
||||
auto sMonth = s.substr(0, firstSep);
|
||||
auto sDay = s.substr(firstSep + 1, lastSep - firstSep - 1);
|
||||
auto sYear = s.substr(lastSep + 1);
|
||||
|
||||
return tryParseYear(sYear, year) && tryParseMonth(sMonth, month) && tryParseDay(sDay, day);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
private:
|
||||
static bool tryParseYearFirst(const std::string& s, int& year, int& month, int& day);
|
||||
static bool tryParseDayFirst(const std::string& s, int& year, int& month, int& day);
|
||||
static bool tryParseMonthFirst(const std::string& s, int& year, int& month, int& day);
|
||||
|
||||
static bool tryParseYear(const std::string& s, int &year);
|
||||
static bool tryParseMonth(const std::string& s, int &month);
|
||||
|
||||
Reference in New Issue
Block a user