##// END OF EJS Templates
Handles incompatibility of Qt::IsoDateWithMs with Qt versions < 5.8
Alexandre Leroux -
r730:8ee7b4704910
parent child
Show More
@@ -24,6 +24,9 const auto RESULT_LINE_SEPARATOR = QRegularExpression{QStringLiteral("\\s+")};
24 24 /// the file
25 25 const auto DATA_HEADER_REGEX = QRegularExpression{QStringLiteral("#\\s*DATA\\s*:")};
26 26
27 /// Format for dates in result files
28 const auto DATE_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss.zzz");
29
27 30 /// Regex to find unit in a line. Examples of valid lines:
28 31 /// ... PARAMETER_UNITS : nT ...
29 32 /// ... PARAMETER_UNITS:nT ...
@@ -31,12 +34,21 const auto DATA_HEADER_REGEX = QRegularExpression{QStringLiteral("#\\s*DATA\\s*:
31 34 /// ... PARAMETER_UNITS : m/s ...
32 35 const auto UNIT_REGEX = QRegularExpression{QStringLiteral("\\s*PARAMETER_UNITS\\s*:\\s*(.+)")};
33 36
37 QDateTime dateTimeFromString(const QString &stringDate) noexcept
38 {
39 #if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
40 return QDateTime::fromString(stringDate, Qt::ISODateWithMs);
41 #else
42 return QDateTime::fromString(stringDate, DATE_FORMAT);
43 #endif
44 }
45
34 46 /// Converts a string date to a double date
35 47 /// @return a double that represents the date in seconds, NaN if the string date can't be converted
36 48 double doubleDate(const QString &stringDate) noexcept
37 49 {
38 50 // Format: yyyy-MM-ddThh:mm:ss.zzz
39 auto dateTime = QDateTime::fromString(stringDate, Qt::ISODateWithMs);
51 auto dateTime = dateTimeFromString(stringDate);
40 52 dateTime.setTimeSpec(Qt::UTC);
41 53 return dateTime.isValid() ? DateUtils::secondsSinceEpoch(dateTime)
42 54 : std::numeric_limits<double>::quiet_NaN();
General Comments 0
You need to be logged in to leave comments. Login now