@@ -0,0 +1,19 | |||||
|
1 | #ifndef SCIQLOP_DATEUTILS_H | |||
|
2 | #define SCIQLOP_DATEUTILS_H | |||
|
3 | ||||
|
4 | #include "CoreGlobal.h" | |||
|
5 | ||||
|
6 | #include <QDateTime> | |||
|
7 | ||||
|
8 | /** | |||
|
9 | * Utility class with methods for dates | |||
|
10 | */ | |||
|
11 | struct SCIQLOP_CORE_EXPORT DateUtils { | |||
|
12 | /// Converts seconds (since epoch) to datetime. By default, the datetime is in UTC | |||
|
13 | static QDateTime dateTime(double secs, Qt::TimeSpec timeSpec = Qt::UTC) noexcept; | |||
|
14 | ||||
|
15 | /// Converts datetime to seconds since epoch | |||
|
16 | static double secondsSinceEpoch(const QDateTime &dateTime) noexcept; | |||
|
17 | }; | |||
|
18 | ||||
|
19 | #endif // SCIQLOP_DATEUTILS_H |
@@ -0,0 +1,13 | |||||
|
1 | #include "Common/DateUtils.h" | |||
|
2 | ||||
|
3 | QDateTime DateUtils::dateTime(double secs, Qt::TimeSpec timeSpec) noexcept | |||
|
4 | { | |||
|
5 | // Uses msecs to be Qt 4 compatible | |||
|
6 | return QDateTime::fromMSecsSinceEpoch(secs * 1000., timeSpec); | |||
|
7 | } | |||
|
8 | ||||
|
9 | double DateUtils::secondsSinceEpoch(const QDateTime &dateTime) noexcept | |||
|
10 | { | |||
|
11 | // Uses msecs to be Qt 4 compatible | |||
|
12 | return dateTime.toMSecsSinceEpoch() / 1000.; | |||
|
13 | } |
General Comments 0
You need to be logged in to leave comments.
Login now