From f81e8612a847e0d9f8b09ccf69eae55daf4f18ec 2017-08-02 15:58:51 From: perrinel Date: 2017-08-02 15:58:51 Subject: [PATCH] Merge pull request #196 from SCIQLOP-Initialisation develop Develop --- diff --git a/app/src/MainWindow.cpp b/app/src/MainWindow.cpp index b38845e..80c94f6 100644 --- a/app/src/MainWindow.cpp +++ b/app/src/MainWindow.cpp @@ -36,7 +36,6 @@ #include #include -#include #include #include #include diff --git a/core/include/Common/DateUtils.h b/core/include/Common/DateUtils.h new file mode 100644 index 0000000..7d80539 --- /dev/null +++ b/core/include/Common/DateUtils.h @@ -0,0 +1,19 @@ +#ifndef SCIQLOP_DATEUTILS_H +#define SCIQLOP_DATEUTILS_H + +#include "CoreGlobal.h" + +#include + +/** + * Utility class with methods for dates + */ +struct SCIQLOP_CORE_EXPORT DateUtils { + /// Converts seconds (since epoch) to datetime. By default, the datetime is in UTC + static QDateTime dateTime(double secs, Qt::TimeSpec timeSpec = Qt::UTC) noexcept; + + /// Converts datetime to seconds since epoch + static double secondsSinceEpoch(const QDateTime &dateTime) noexcept; +}; + +#endif // SCIQLOP_DATEUTILS_H diff --git a/core/include/Data/IDataSeries.h b/core/include/Data/IDataSeries.h index 5dfa75a..2710e1b 100644 --- a/core/include/Data/IDataSeries.h +++ b/core/include/Data/IDataSeries.h @@ -23,7 +23,7 @@ struct Unit { inline bool operator!=(const Unit &other) const { return !(*this == other); } QString m_Name; ///< Unit name - bool m_TimeUnit; ///< The unit is a unit of time + bool m_TimeUnit; ///< The unit is a unit of time (UTC) }; /** diff --git a/core/include/Data/SqpDateTime.h b/core/include/Data/SqpDateTime.h index 3ea0484..b4c51c5 100644 --- a/core/include/Data/SqpDateTime.h +++ b/core/include/Data/SqpDateTime.h @@ -3,18 +3,18 @@ #include -#include #include +#include #include /** * @brief The SqpDateTime struct holds the information of time parameters */ struct SqpDateTime { - /// Start time + /// Start time (UTC) double m_TStart; - /// End time + /// End time (UTC) double m_TEnd; bool contains(const SqpDateTime &dateTime) const noexcept @@ -30,10 +30,9 @@ struct SqpDateTime { inline QDebug operator<<(QDebug d, SqpDateTime obj) { - auto tendDateTimeStart = QDateTime::fromMSecsSinceEpoch(obj.m_TStart * 1000); - auto tendDateTimeEnd = QDateTime::fromMSecsSinceEpoch(obj.m_TEnd * 1000); + auto tendDateTimeStart = DateUtils::dateTime(obj.m_TStart); + auto tendDateTimeEnd = DateUtils::dateTime(obj.m_TEnd); - // QDebug << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd; d << "ts: " << tendDateTimeStart << " te: " << tendDateTimeEnd; return d; } diff --git a/core/src/Common/DateUtils.cpp b/core/src/Common/DateUtils.cpp new file mode 100644 index 0000000..635bbf2 --- /dev/null +++ b/core/src/Common/DateUtils.cpp @@ -0,0 +1,13 @@ +#include "Common/DateUtils.h" + +QDateTime DateUtils::dateTime(double secs, Qt::TimeSpec timeSpec) noexcept +{ + // Uses msecs to be Qt 4 compatible + return QDateTime::fromMSecsSinceEpoch(secs * 1000., timeSpec); +} + +double DateUtils::secondsSinceEpoch(const QDateTime &dateTime) noexcept +{ + // Uses msecs to be Qt 4 compatible + return dateTime.toMSecsSinceEpoch() / 1000.; +} diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index c439435..e69b4de 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -8,7 +8,6 @@ #include #include