diff --git a/cmake/CommonModules/TinyCommon.cmake b/cmake/CommonModules/TinyCommon.cmake index 498651f83..2a7c27731 100644 --- a/cmake/CommonModules/TinyCommon.cmake +++ b/cmake/CommonModules/TinyCommon.cmake @@ -28,8 +28,8 @@ ${TINY_UNPARSED_ARGUMENTS}") # Disable deprecated APIs up to the given Qt version # TODO qt5 remove silverqx if(QT_VERSION_MAJOR GREATER_EQUAL 6) - # Disable all the APIs deprecated up to Qt v6.7.0 (including) - target_compile_definitions(${target} INTERFACE QT_DISABLE_DEPRECATED_UP_TO=0x060700) + # Disable all the APIs deprecated up to Qt v6.9.0 (including) + target_compile_definitions(${target} INTERFACE QT_DISABLE_DEPRECATED_UP_TO=0x060900) else() # Disable all the APIs deprecated up to Qt v6.0.0 (including) target_compile_definitions(${target} INTERFACE QT_DISABLE_DEPRECATED_BEFORE=0x060000) @@ -37,6 +37,9 @@ ${TINY_UNPARSED_ARGUMENTS}") target_compile_definitions(${target} INTERFACE + #QT_NO_DEPRECATED_WARNINGS + #QT_WARN_DEPRECATED_UP_TO=0x060900 + #QT_ASCII_CAST_WARNINGS #QT_NO_CAST_FROM_ASCII #QT_RESTRICTED_CAST_FROM_ASCII diff --git a/examples/tom/main.cpp b/examples/tom/main.cpp index 6c81bc0c2..47069ac6a 100644 --- a/examples/tom/main.cpp +++ b/examples/tom/main.cpp @@ -12,6 +12,7 @@ using Orm::DatabaseManager; using Orm::DB; +using Orm::QtTimeZoneConfig; using ConfigUtils = Orm::Utils::Configuration; @@ -86,7 +87,7 @@ std::shared_ptr setupDatabaseManager() /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + {qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())}, {prefix_, EMPTY}, {prefix_indexes, false}, {strict_, true}, @@ -112,7 +113,7 @@ std::shared_ptr setupDatabaseManager() /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + {qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())}, {prefix_, EMPTY}, {prefix_indexes, false}, {strict_, true}, @@ -139,7 +140,7 @@ std::shared_ptr setupDatabaseManager() /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + {qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())}, // Examples of qt_timezone // {qt_timezone, QVariant::fromValue(QTimeZone("Europe/Bratislava"))}, // {qt_timezone, "Europe/Prague"}, // Will be converted to QTimeZone("Europe/Prague") @@ -167,7 +168,7 @@ std::shared_ptr setupDatabaseManager() /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + {qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())}, /* Return a QDateTime/QDate with the correct time zone instead of the QString, only works when the qt_timezone isn't set to the DontConvert. */ {return_qdatetime, true}, diff --git a/include/orm/connectors/connectionfactory.hpp b/include/orm/connectors/connectionfactory.hpp index 94ed9b92d..ad65de48f 100644 --- a/include/orm/connectors/connectionfactory.hpp +++ b/include/orm/connectors/connectionfactory.hpp @@ -66,7 +66,7 @@ namespace Connectors createConnection( const QString &driver, std::function &&connection, QString &&database, QString &&tablePrefix = "", - QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC}, + QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(), QVariantHash &&config = {}, std::optional returnQDateTime = std::nullopt); diff --git a/include/orm/databaseconnection.hpp b/include/orm/databaseconnection.hpp index 144a11ceb..9e775b444 100644 --- a/include/orm/databaseconnection.hpp +++ b/include/orm/databaseconnection.hpp @@ -74,13 +74,13 @@ namespace Orm explicit DatabaseConnection( std::function &&connection, QString &&database = "", QString &&tablePrefix = "", - QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC}, + QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(), QVariantHash &&config = {}); /*! Protected constructor for SQLite connection. */ explicit DatabaseConnection( std::function &&connection, QString &&database = "", QString &&tablePrefix = "", - QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC}, + QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(), std::optional returnQDateTime = true, QVariantHash &&config = {}); diff --git a/include/orm/mysqlconnection.hpp b/include/orm/mysqlconnection.hpp index ba62fa233..bad3d9461 100644 --- a/include/orm/mysqlconnection.hpp +++ b/include/orm/mysqlconnection.hpp @@ -21,7 +21,7 @@ namespace Orm explicit MySqlConnection( std::function &&connection, QString &&database = "", QString &&tablePrefix = "", - QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC}, + QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(), QVariantHash &&config = {}); public: @@ -33,7 +33,7 @@ namespace Orm std::shared_ptr create(std::function &&connection, QString &&database = "", QString &&tablePrefix = "", - QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC}, + QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(), QVariantHash &&config = {}); /* Getters / Setters */ diff --git a/include/orm/ormtypes.hpp b/include/orm/ormtypes.hpp index 3fd0bcc78..ef26e53c6 100644 --- a/include/orm/ormtypes.hpp +++ b/include/orm/ormtypes.hpp @@ -177,25 +177,74 @@ namespace Query { /*! Don't convert time zone. */ DontConvert, - /*! QtTimeZoneConfig contains Qt::TimeSpec, use toTimeSpec() for conversion. */ - QtTimeSpec, /*! QtTimeZoneConfig contains the QTimeZone, use toTimeZone() for conversion. */ QTimeZone, /*! QtTimeZoneConfig contains seconds, use toOffsetFromUtc() for conversion. */ OffsetFromUtc, +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) + /*! QtTimeZoneConfig contains Qt::TimeSpec, use toTimeSpec() for conversion. */ + QtTimeSpec, +#endif }; +/* The TTimeZone alias can be used on Qt v5, Qt =v6.5. + It helps to support all Qt versions still. */ +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + /*! Alias for QTimeZone::Initialization. */ + using TTimeZone = QTimeZone::Initialization; +#else + /*! Alias for Qt::TimeSpec. */ + using TTimeZone = Qt::TimeSpec; +#endif + /*! Determine how the QDateTime time zone will be converted, it's saved in the qt_timezone database connection's configuration option. */ struct QtTimeZoneConfig { +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + /*! Time zone type saved in the value data member. */ + QtTimeZoneType type {QtTimeZoneType::QTimeZone}; + /*! Time zone value (UTC by default). */ + QVariant value {QVariant::fromValue(QTimeZone(QTimeZone::UTC))}; // UTC is the default timezone, not the QTimeZone::LocalTime (it overrides this default) +#else /*! Time zone type saved in the value data member. */ QtTimeZoneType type {QtTimeZoneType::QtTimeSpec}; - /*! Time zone value. */ + /*! Time zone value (UTC by default). */ QVariant value {Qt::UTC}; // UTC is the default timezone, not the Qt::LocalTime (it overrides this default) +#endif /*! Equality comparison operator for the QtTimeZoneConfig. */ bool operator==(const QtTimeZoneConfig &) const = default; + + /*! Factory method to create QtTimeZoneConfig as QTimeZone::UTC instance. */ +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + inline static QtTimeZoneConfig utc() noexcept +#else + inline static QtTimeZoneConfig utc() +#endif + { +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + return {QtTimeZoneType::QTimeZone, + QVariant::fromValue(QTimeZone(QTimeZone::UTC))}; +#else + return {QtTimeZoneType::QtTimeSpec, Qt::UTC}; +#endif + } + + /*! Factory method to create QtTimeZoneConfig as QTimeZone::LocalTime instance. */ +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + inline static QtTimeZoneConfig localTime() noexcept +#else + inline static QtTimeZoneConfig localTime() +#endif + { +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + return {QtTimeZoneType::QTimeZone, + QVariant::fromValue(QTimeZone(QTimeZone::LocalTime))}; +#else + return {QtTimeZoneType::QtTimeSpec, Qt::LocalTime}; +#endif + } }; } // namespace Orm diff --git a/include/orm/postgresconnection.hpp b/include/orm/postgresconnection.hpp index 22caedfca..0a8c8dca1 100644 --- a/include/orm/postgresconnection.hpp +++ b/include/orm/postgresconnection.hpp @@ -23,7 +23,7 @@ namespace Orm explicit PostgresConnection( std::function &&connection, QString &&database = "", QString &&tablePrefix = "", - QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC}, + QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(), QVariantHash &&config = {}); public: @@ -35,7 +35,7 @@ namespace Orm std::shared_ptr create(std::function &&connection, QString &&database = "", QString &&tablePrefix = "", - QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC}, + QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(), QVariantHash &&config = {}); /* Getters */ diff --git a/include/orm/sqliteconnection.hpp b/include/orm/sqliteconnection.hpp index 05d3efff5..abbd891fd 100644 --- a/include/orm/sqliteconnection.hpp +++ b/include/orm/sqliteconnection.hpp @@ -21,7 +21,7 @@ namespace Orm explicit SQLiteConnection( std::function &&connection, QString &&database = "", QString &&tablePrefix = "", - QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC}, + QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(), std::optional returnQDateTime = true, QVariantHash &&config = {}); @@ -34,7 +34,7 @@ namespace Orm std::shared_ptr create(std::function &&connection, QString &&database = "", QString &&tablePrefix = "", - QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC}, + QtTimeZoneConfig &&qtTimeZone = QtTimeZoneConfig::utc(), std::optional returnQDateTime = true, QVariantHash &&config = {}); diff --git a/qmake/common/common.pri b/qmake/common/common.pri index d999cdc7b..20c252a86 100644 --- a/qmake/common/common.pri +++ b/qmake/common/common.pri @@ -21,14 +21,17 @@ CONFIG -= c++11 app_bundle # --- # Disable deprecated APIs up to the given Qt version -# Disable all the APIs deprecated up to Qt v6.7.0 (including) +# Disable all the APIs deprecated up to Qt v6.9.0 (including) # TODO qt5 remove silverqx versionAtLeast(QT_VERSION, 6): \ - DEFINES *= QT_DISABLE_DEPRECATED_UP_TO=0x060800 + DEFINES *= QT_DISABLE_DEPRECATED_UP_TO=0x060900 # Disable all the APIs deprecated up to Qt v6.0.0 (including) else: \ DEFINES *= QT_DISABLE_DEPRECATED_BEFORE=0x060000 +#DEFINES *= QT_NO_DEPRECATED_WARNINGS +#DEFINES *= QT_WARN_DEPRECATED_UP_TO=0x060900 + #DEFINES *= QT_ASCII_CAST_WARNINGS #DEFINES *= QT_NO_CAST_FROM_ASCII #DEFINES *= QT_RESTRICTED_CAST_FROM_ASCII diff --git a/src/orm/utils/configuration.cpp b/src/orm/utils/configuration.cpp index 095dcd826..94195bc4a 100644 --- a/src/orm/utils/configuration.cpp +++ b/src/orm/utils/configuration.cpp @@ -42,7 +42,7 @@ QtTimeZoneConfig Configuration::prepareQtTimeZone(const QVariantHash &config, const QString &connection) { if (!config.contains(qt_timezone)) - return {QtTimeZoneType::QtTimeSpec, Qt::UTC}; + return QtTimeZoneConfig::utc(); return prepareQtTimeZone(config[qt_timezone], connection); } @@ -52,12 +52,23 @@ Configuration::prepareQtTimeZone(const QVariant &qtTimeZone, const QString &conn { // Nothing to do if (!qtTimeZone.isValid() || qtTimeZone.isNull()) - return {QtTimeZoneType::QtTimeSpec, Qt::UTC}; + return QtTimeZoneConfig::utc(); const auto typeId = Helpers::qVariantTypeId(qtTimeZone); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + if (typeId == QMetaType::fromType().id()) + return {QtTimeZoneType::QTimeZone, + QVariant::fromValue( + QTimeZone(qtTimeZone.value()))}; +#else if (typeId == QMetaType::fromType().id()) return {QtTimeZoneType::QtTimeSpec, qtTimeZone.value()}; +#endif + + if (typeId == QMetaType::fromType().id()) + return {QtTimeZoneType::QTimeZone, + QVariant::fromValue(qtTimeZone.value())}; // Allow to define the QtTimeZoneType::DontConvert for the qt_timezone config. option if (typeId == QMetaType::fromType().id()) @@ -66,10 +77,6 @@ Configuration::prepareQtTimeZone(const QVariant &qtTimeZone, const QString &conn ) return {QtTimeZoneType::DontConvert, {}}; - if (typeId == QMetaType::fromType().id()) - return {QtTimeZoneType::QTimeZone, - QVariant::fromValue(qtTimeZone.value())}; - /* Must be a valid IANA timezone ID and must be available on a current system. Also if a configuration option is the QString then return the QTimeZone right away, to avoid re-computations in the Connection::prepareBinding(). */ diff --git a/src/orm/utils/helpers.cpp b/src/orm/utils/helpers.cpp index cd9ed387b..15b35a81b 100644 --- a/src/orm/utils/helpers.cpp +++ b/src/orm/utils/helpers.cpp @@ -86,12 +86,25 @@ Helpers::convertTimeZone(const QDateTime &datetime, const QtTimeZoneConfig &time switch (timezoneType) { T_LIKELY - case QtTimeZoneType::QtTimeSpec: - return datetime.toTimeSpec(timezoneValue.value()); + case QtTimeZoneType::QTimeZone: +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + if (const auto typeId = Helpers::qVariantTypeId(timezoneValue); + typeId == QMetaType::fromType().id() + ) + return datetime.toTimeZone(timezoneValue.value()); + else if (typeId == QMetaType::fromType().id()) +#endif + return datetime.toTimeZone(timezoneValue.value()); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + else + Q_UNREACHABLE(); +#endif +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) T_LIKELY - case QtTimeZoneType::QTimeZone: - return datetime.toTimeZone(timezoneValue.value()); + case QtTimeZoneType::QtTimeSpec: + return datetime.toTimeSpec(timezoneValue.value()); +#endif T_UNLIKELY case QtTimeZoneType::OffsetFromUtc: @@ -110,19 +123,32 @@ Helpers::setTimeZone(QDateTime &datetime, const QtTimeZoneConfig &timezone) switch (timezoneType) { T_LIKELY - case QtTimeZoneType::QtTimeSpec: - datetime.setTimeSpec(timezoneValue.value()); + case QtTimeZoneType::QTimeZone: +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + if (const auto typeId = Helpers::qVariantTypeId(timezoneValue); + typeId == QMetaType::fromType().id() + ) + datetime.setTimeZone(timezoneValue.value()); + else if (typeId == QMetaType::fromType().id()) +#endif + datetime.setTimeZone(timezoneValue.value()); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + else + Q_UNREACHABLE(); +#endif break; +#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0) T_LIKELY - case QtTimeZoneType::QTimeZone: - datetime.setTimeZone(timezoneValue.value()); + case QtTimeZoneType::QtTimeSpec: + datetime.setTimeSpec(timezoneValue.value()); break; T_UNLIKELY case QtTimeZoneType::OffsetFromUtc: datetime.setOffsetFromUtc(timezoneValue.value()); break; +#endif T_UNLIKELY default: diff --git a/tests/TinyUtils/src/databases.cpp b/tests/TinyUtils/src/databases.cpp index c3d15e253..cfc193baa 100644 --- a/tests/TinyUtils/src/databases.cpp +++ b/tests/TinyUtils/src/databases.cpp @@ -73,6 +73,7 @@ using Orm::Constants::SSL_MODE; using Orm::DB; using Orm::DatabaseManager; using Orm::Exceptions::RuntimeError; +using Orm::TTimeZone; using ConfigUtils = Orm::Utils::Configuration; @@ -645,8 +646,11 @@ Databases::mysqlConfiguration() {timezone_, TZ00}, /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to - use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + use the system local time. + Also, don't use the QtTimeZoneConfig::utc() here because + of tst_DatabaseConnection::timezone_And_qt_timezone() test to pass, we need to + test if the value is correctly parsed. */ + {qt_timezone, QVariant::fromValue(TTimeZone::UTC)}, {prefix_, EMPTY}, {prefix_indexes, false}, {strict_, true}, @@ -683,8 +687,11 @@ Databases::mariaConfiguration() {timezone_, TZ00}, /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to - use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + use the system local time. + Also, don't use the QtTimeZoneConfig::utc() here because + of tst_DatabaseConnection::timezone_And_qt_timezone() test to pass, we need to + test if the value is correctly parsed. */ + {qt_timezone, QVariant::fromValue(TTimeZone::UTC)}, {prefix_, EMPTY}, {prefix_indexes, false}, {strict_, true}, @@ -713,8 +720,11 @@ Databases::sqliteConfiguration() {check_database_exists, true}, /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to - use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + use the system local time. + Also, don't use the QtTimeZoneConfig::utc() here because + of tst_DatabaseConnection::timezone_And_qt_timezone() test to pass, we need to + test if the value is correctly parsed. */ + {qt_timezone, QVariant::fromValue(TTimeZone::UTC)}, /* Return a QDateTime with the correct time zone instead of the QString, only works when the qt_timezone isn't set to the DontConvert. */ {return_qdatetime, true}, @@ -742,8 +752,11 @@ Databases::postgresConfiguration() {timezone_, UTC}, /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to - use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + use the system local time. + Also, don't use the QtTimeZoneConfig::utc() here because + of tst_DatabaseConnection::timezone_And_qt_timezone() test to pass, we need to + test if the value is correctly parsed. */ + {qt_timezone, QVariant::fromValue(TTimeZone::UTC)}, {prefix_, EMPTY}, {prefix_indexes, false}, // {isolation_level, sl("REPEATABLE READ")}, // Postgres default is READ COMMITTED diff --git a/tests/auto/functional/orm/databasemanager/tst_databasemanager.cpp b/tests/auto/functional/orm/databasemanager/tst_databasemanager.cpp index 48c3b9950..ca749041c 100644 --- a/tests/auto/functional/orm/databasemanager/tst_databasemanager.cpp +++ b/tests/auto/functional/orm/databasemanager/tst_databasemanager.cpp @@ -104,7 +104,7 @@ private Q_SLOTS: /*! The QtTimeZoneConfig set to the Qt::UTC. */ Q_GLOBAL_STATIC_WITH_ARGS( const QVariant, QtTimeZoneConfigUTC, // NOLINT(misc-use-anonymous-namespace, cppcoreguidelines-avoid-non-const-global-variables) - (QVariant::fromValue(QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, Qt::UTC}))) + (QVariant::fromValue(QtTimeZoneConfig::utc()))) /*! QString constant for the "users" table. */ Q_GLOBAL_STATIC_WITH_ARGS(const QString, UsersTable, ("users")) // NOLINT(misc-use-anonymous-namespace, cppcoreguidelines-avoid-non-const-global-variables) diff --git a/tests/auto/functional/orm/query/mysql_qdatetime/tst_mysql_qdatetime.cpp b/tests/auto/functional/orm/query/mysql_qdatetime/tst_mysql_qdatetime.cpp index 69e47b743..5b13112dd 100644 --- a/tests/auto/functional/orm/query/mysql_qdatetime/tst_mysql_qdatetime.cpp +++ b/tests/auto/functional/orm/query/mysql_qdatetime/tst_mysql_qdatetime.cpp @@ -24,6 +24,7 @@ using Orm::Constants::UTC; using Orm::DB; using Orm::QtTimeZoneConfig; using Orm::QtTimeZoneType; +using Orm::TTimeZone; using Orm::Utils::Helpers; using Orm::Utils::NullVariant; @@ -233,7 +234,7 @@ insert_Qt_QDateTime_UtcTimezone_DatetimeColumn_UtcOnServer() const QVERIFY(qtQuery.prepare("insert into `datetimes` (`datetime`) values (?)")); - qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)); // QMYSQL driver doesn't care about QDateTime timezone QVERIFY(qtQuery.exec()); @@ -274,7 +275,8 @@ insert_Qt_QDateTime_UtcTimezone_DatetimeColumn_UtcOnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto datetimeActual = datetimeDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, QTimeZone::UTC); @@ -347,7 +349,8 @@ insert_Qt_QDateTime_0200Timezone_DatetimeColumn_UtcOnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto datetimeActual = datetimeDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, QTimeZone::UTC); @@ -418,7 +421,8 @@ void tst_MySql_QDateTime::insert_Qt_QString_DatetimeColumn_UtcOnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto datetimeActual = datetimeDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, QTimeZone::UTC); @@ -450,7 +454,7 @@ insert_Qt_QDateTime_UtcTimezone_TimestampColumn_UtcOnServer() const QVERIFY(qtQuery.prepare("insert into `datetimes` (`timestamp`) values (?)")); - qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, TTimeZone::UTC)); // QMYSQL driver doesn't care about QDateTime timezone QVERIFY(qtQuery.exec()); @@ -491,7 +495,8 @@ insert_Qt_QDateTime_UtcTimezone_TimestampColumn_UtcOnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto timestampActual = timestampDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto timestampExpected = QDateTime({2022, 8, 29}, {13, 14, 15}, QTimeZone::UTC); @@ -564,7 +569,8 @@ insert_Qt_QDateTime_0200Timezone_TimestampColumn_UtcOnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto timestampActual = timestampDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto timestampExpected = QDateTime({2022, 8, 29}, {11, 14, 15}, QTimeZone::UTC); @@ -636,7 +642,8 @@ void tst_MySql_QDateTime::insert_Qt_QString_TimestampColumn_UtcOnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto timestampActual = timestampDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto timestampExpected = QDateTime({2022, 8, 29}, {13, 14, 15}, QTimeZone::UTC); @@ -671,7 +678,7 @@ insert_Qt_QDateTime_UtcTimezone_DatetimeColumn_0200OnServer() const QVERIFY(qtQuery.prepare("insert into `datetimes` (`datetime`) values (?)")); - qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)); // QMYSQL driver doesn't care about QDateTime timezone QVERIFY(qtQuery.exec()); @@ -712,7 +719,8 @@ insert_Qt_QDateTime_UtcTimezone_DatetimeColumn_0200OnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto datetimeActual = datetimeDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, QTimeZone::UTC); @@ -786,7 +794,8 @@ insert_Qt_QDateTime_0200Timezone_DatetimeColumn_0200OnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto datetimeActual = datetimeDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, QTimeZone::UTC); @@ -858,7 +867,8 @@ void tst_MySql_QDateTime::insert_Qt_QString_DatetimeColumn_0200OnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto datetimeActual = datetimeDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, QTimeZone::UTC); @@ -891,7 +901,7 @@ insert_Qt_QDateTime_UtcTimezone_TimestampColumn_0200OnServer() const QVERIFY(qtQuery.prepare("insert into `datetimes` (`timestamp`) values (?)")); - qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, TTimeZone::UTC)); // QMYSQL driver doesn't care about QDateTime timezone QVERIFY(qtQuery.exec()); @@ -932,7 +942,8 @@ insert_Qt_QDateTime_UtcTimezone_TimestampColumn_0200OnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto timestampActual = timestampDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto timestampExpected = QDateTime({2022, 8, 29}, {13, 14, 15}, QTimeZone::UTC); @@ -1006,7 +1017,8 @@ insert_Qt_QDateTime_0200Timezone_TimestampColumn_0200OnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto timestampActual = timestampDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto timestampExpected = QDateTime({2022, 8, 29}, {11, 14, 15}, QTimeZone::UTC); @@ -1078,7 +1090,8 @@ void tst_MySql_QDateTime::insert_Qt_QString_TimestampColumn_0200OnServer() const /* QMYSQL driver doesn't care about QDateTime timezone and returns the QDateTime in a local timezone. */ const auto timestampActual = timestampDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto timestampExpected = QDateTime({2022, 8, 29}, {13, 14, 15}, QTimeZone::UTC); @@ -1109,7 +1122,7 @@ insert_QDateTime_UtcTimezone_DatetimeColumn_UtcOnServer() const // Insert quint64 lastId = createQuery(connection)->from(*datetimes).insertGetId( {{*datetime, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -1130,7 +1143,8 @@ insert_QDateTime_UtcTimezone_DatetimeColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QMYSQL driver. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -1170,7 +1184,8 @@ insert_QDateTime_0200Timezone_DatetimeColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QMYSQL driver. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -1208,7 +1223,8 @@ void tst_MySql_QDateTime::insert_QString_DatetimeColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QMYSQL driver. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -1227,7 +1243,7 @@ insert_QDateTime_UtcTimezone_TimestampColumn_UtcOnServer() const // Insert quint64 lastId = createQuery(connection)->from(*datetimes).insertGetId( {{*timestamp, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -1248,7 +1264,8 @@ insert_QDateTime_UtcTimezone_TimestampColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QMYSQL driver. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -1288,7 +1305,8 @@ insert_QDateTime_0200Timezone_TimestampColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QMYSQL driver. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -1326,7 +1344,8 @@ void tst_MySql_QDateTime::insert_QString_TimestampColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QMYSQL driver. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -1349,7 +1368,7 @@ insert_QDateTime_UtcTimezone_DatetimeColumn_0200OnServer() const // Insert quint64 lastId = createQuery(connection)->from(*datetimes).insertGetId( {{*datetime, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -1473,7 +1492,7 @@ insert_QDateTime_UtcTimezone_TimestampColumn_0200OnServer() const // Insert quint64 lastId = createQuery(connection)->from(*datetimes).insertGetId( {{*timestamp, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -2985,7 +3004,8 @@ insert_QDateTime_0300Timezone_DatetimeColumn_UtcOnServer_DontConvert() const // Practically it should behave as is the default QMYSQL driver behavior const auto datetimeActual = datetimeDbVariant.value(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, QTimeZone::UTC); @@ -3024,8 +3044,7 @@ TSqlQuery tst_MySql_QDateTime::createQtQuery(const QString &connection) void tst_MySql_QDateTime::setUtcTimezone(const QString &connection) { - setTimezone(connection, utcTimezoneString(connection), - {QtTimeZoneType::QtTimeSpec, QVariant::fromValue(Qt::UTC)}); + setTimezone(connection, utcTimezoneString(connection), QtTimeZoneConfig::utc()); } void tst_MySql_QDateTime::set0200Timezone(const QString &connection) diff --git a/tests/auto/functional/orm/query/postgresql_qdatetime/tst_postgresql_qdatetime.cpp b/tests/auto/functional/orm/query/postgresql_qdatetime/tst_postgresql_qdatetime.cpp index 3fd015b59..42ec80b8f 100644 --- a/tests/auto/functional/orm/query/postgresql_qdatetime/tst_postgresql_qdatetime.cpp +++ b/tests/auto/functional/orm/query/postgresql_qdatetime/tst_postgresql_qdatetime.cpp @@ -18,6 +18,7 @@ using Orm::Constants::UTC; using Orm::DB; using Orm::QtTimeZoneConfig; using Orm::QtTimeZoneType; +using Orm::TTimeZone; using Orm::Utils::Helpers; using Orm::Utils::NullVariant; @@ -204,7 +205,7 @@ insert_Qt_QDateTime_UtcTimezone_DatetimeColumn_UtcOnServer() const QVERIFY(qtQuery.prepare(R"(insert into "datetimes" ("datetime") values (?))")); - qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)); QVERIFY(qtQuery.exec()); @@ -414,7 +415,7 @@ insert_Qt_QDateTime_UtcTimezone_TimestampColumn_UtcOnServer() const QVERIFY(qtQuery.prepare(R"(insert into "datetimes" ("timestamp") values (?))")); - qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, TTimeZone::UTC)); // QPSQL driver converts the QDateTime time zone to UTC QVERIFY(qtQuery.exec()); @@ -627,7 +628,7 @@ insert_Qt_QDateTime_UtcTimezone_DatetimeColumn_0200OnServer() const QVERIFY(qtQuery.prepare(R"(insert into "datetimes" ("datetime") values (?))")); - qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)); QVERIFY(qtQuery.exec()); @@ -840,7 +841,7 @@ insert_Qt_QDateTime_UtcTimezone_TimestampColumn_0200OnServer() const QVERIFY(qtQuery.prepare(R"(insert into "datetimes" ("timestamp") values (?))")); - qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, TTimeZone::UTC)); // QPSQL driver converts the QDateTime time zone to UTC QVERIFY(qtQuery.exec()); @@ -1051,7 +1052,7 @@ insert_QDateTime_UtcTimezone_DatetimeColumn_UtcOnServer() const // Insert quint64 lastId = createQuery()->from(*datetimes).insertGetId( {{*datetime, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -1071,7 +1072,8 @@ insert_QDateTime_UtcTimezone_DatetimeColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QPSQL driver. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -1109,7 +1111,8 @@ insert_QDateTime_0200Timezone_DatetimeColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QPSQL driver. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -1144,7 +1147,8 @@ void tst_PostgreSQL_QDateTime::insert_QString_DatetimeColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QPSQL driver. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -1161,7 +1165,7 @@ insert_QDateTime_UtcTimezone_TimestampColumn_UtcOnServer() const // Insert quint64 lastId = createQuery()->from(*datetimes).insertGetId( {{*timestamp, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -1181,7 +1185,8 @@ insert_QDateTime_UtcTimezone_TimestampColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QPSQL driver. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -1219,7 +1224,8 @@ insert_QDateTime_0200Timezone_TimestampColumn_UtcOnServer() const configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QPSQL driver. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -1254,7 +1260,8 @@ void tst_PostgreSQL_QDateTime::insert_QString_TimestampColumn_UtcOnServer() cons configuration, TinyORM QueryBuilder fixes the buggy time zone behavior of the QPSQL driver. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -1275,7 +1282,7 @@ insert_QDateTime_UtcTimezone_DatetimeColumn_0200OnServer() const // Insert quint64 lastId = createQuery()->from(*datetimes).insertGetId( {{*datetime, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -1391,7 +1398,7 @@ insert_QDateTime_UtcTimezone_TimestampColumn_0200OnServer() const // Insert quint64 lastId = createQuery()->from(*datetimes).insertGetId( {{*timestamp, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -2865,7 +2872,7 @@ TSqlQuery tst_PostgreSQL_QDateTime::createQtQuery() const void tst_PostgreSQL_QDateTime::setUtcTimezone() const { - setTimezone(UTC, {QtTimeZoneType::QtTimeSpec, QVariant::fromValue(Qt::UTC)}); + setTimezone(UTC, QtTimeZoneConfig::utc()); } void tst_PostgreSQL_QDateTime::setEUBratislavaTimezone() const diff --git a/tests/auto/functional/orm/query/querybuilder/tst_querybuilder.cpp b/tests/auto/functional/orm/query/querybuilder/tst_querybuilder.cpp index a3ac2c666..3f27325e8 100644 --- a/tests/auto/functional/orm/query/querybuilder/tst_querybuilder.cpp +++ b/tests/auto/functional/orm/query/querybuilder/tst_querybuilder.cpp @@ -32,6 +32,7 @@ using Orm::Exceptions::MultipleRecordsFoundError; using Orm::Exceptions::RecordsNotFoundError; using Orm::Exceptions::RuntimeError; using Orm::Query::Builder; +using Orm::TTimeZone; using Orm::Types::SqlQuery; using QueryBuilder = Orm::Query::Builder; @@ -542,9 +543,9 @@ void tst_QueryBuilder::whereDate_QDate() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -563,7 +564,7 @@ void tst_QueryBuilder::whereDate_QDateTime() auto result = createQuery(connection)->from("torrents") .whereDate(CREATED_AT, LE, // QTime part is ignored - QDateTime({2018, 8, 3}, {}, Qt::UTC)) + QDateTime({2018, 8, 3}, {}, TTimeZone::UTC)) .orderBy(CREATED_AT) .get(); @@ -571,9 +572,9 @@ void tst_QueryBuilder::whereDate_QDateTime() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -598,9 +599,9 @@ void tst_QueryBuilder::whereDate_QString() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -625,9 +626,9 @@ void tst_QueryBuilder::whereTime_QTime() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -646,7 +647,7 @@ void tst_QueryBuilder::whereTime_QDateTime() auto result = createQuery(connection)->from("torrents") .whereTime(CREATED_AT, LE, // QDate part is ignored - QDateTime({}, {8, 10, 23}, Qt::UTC)) + QDateTime({}, {8, 10, 23}, TTimeZone::UTC)) .orderBy(CREATED_AT) .get(); @@ -654,9 +655,9 @@ void tst_QueryBuilder::whereTime_QDateTime() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -681,9 +682,9 @@ void tst_QueryBuilder::whereTime_QString() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -708,9 +709,9 @@ void tst_QueryBuilder::whereDay_QDate() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -727,7 +728,7 @@ void tst_QueryBuilder::whereDay_QDateTime() QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits) auto result = createQuery(connection)->from("torrents") - .whereDay(CREATED_AT, LE, QDateTime({2018, 8, 3}, {}, Qt::UTC)) + .whereDay(CREATED_AT, LE, QDateTime({2018, 8, 3}, {}, TTimeZone::UTC)) .orderBy(CREATED_AT) .get(); @@ -735,9 +736,9 @@ void tst_QueryBuilder::whereDay_QDateTime() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -762,9 +763,9 @@ void tst_QueryBuilder::whereDay_QString() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -789,9 +790,9 @@ void tst_QueryBuilder::whereDay_int() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -816,9 +817,9 @@ void tst_QueryBuilder::whereMonth_QDate() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -835,7 +836,7 @@ void tst_QueryBuilder::whereMonth_QDateTime() QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits) auto result = createQuery(connection)->from("torrents") - .whereMonth(CREATED_AT, LE, QDateTime({2018, 8, 3}, {}, Qt::UTC)) + .whereMonth(CREATED_AT, LE, QDateTime({2018, 8, 3}, {}, TTimeZone::UTC)) .orderBy(CREATED_AT) .get(); @@ -843,9 +844,9 @@ void tst_QueryBuilder::whereMonth_QDateTime() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -870,9 +871,9 @@ void tst_QueryBuilder::whereMonth_QString() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -897,9 +898,9 @@ void tst_QueryBuilder::whereMonth_int() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -924,9 +925,9 @@ void tst_QueryBuilder::whereYear_QDate() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -943,7 +944,7 @@ void tst_QueryBuilder::whereYear_QDateTime() QFETCH_GLOBAL(QString, connection); // NOLINT(modernize-type-traits) auto result = createQuery(connection)->from("torrents") - .whereYear(CREATED_AT, LE, QDateTime({2018, 8, 3}, {}, Qt::UTC)) + .whereYear(CREATED_AT, LE, QDateTime({2018, 8, 3}, {}, TTimeZone::UTC)) .orderBy(CREATED_AT) .get(); @@ -951,9 +952,9 @@ void tst_QueryBuilder::whereYear_QDateTime() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -978,9 +979,9 @@ void tst_QueryBuilder::whereYear_QString() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; @@ -1005,9 +1006,9 @@ void tst_QueryBuilder::whereYear_int() QCOMPARE(QueryUtils::queryResultSize(result), 3); QVector expectedCreatedAts { - QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC), - QDateTime({2017, 7, 2}, {8, 9, 23}, Qt::UTC), - QDateTime({2018, 8, 3}, {8, 10, 23}, Qt::UTC), + QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC), + QDateTime({2017, 7, 2}, {8, 9, 23}, TTimeZone::UTC), + QDateTime({2018, 8, 3}, {8, 10, 23}, TTimeZone::UTC), }; QVector actualCreatedAts; diff --git a/tests/auto/functional/orm/query/sqlite_qdatetime/tst_sqlite_qdatetime.cpp b/tests/auto/functional/orm/query/sqlite_qdatetime/tst_sqlite_qdatetime.cpp index 24c3f6fd4..4f1e7e826 100644 --- a/tests/auto/functional/orm/query/sqlite_qdatetime/tst_sqlite_qdatetime.cpp +++ b/tests/auto/functional/orm/query/sqlite_qdatetime/tst_sqlite_qdatetime.cpp @@ -18,6 +18,7 @@ using Orm::DB; using Orm::QtTimeZoneConfig; using Orm::QtTimeZoneType; using Orm::SQLiteConnection; +using Orm::TTimeZone; using Orm::Utils::Helpers; using Orm::Utils::NullVariant; @@ -197,7 +198,7 @@ insert_Qt_QDateTime_UtcTimezone_DatetimeColumn() const QVERIFY(qtQuery.prepare(R"(insert into "datetimes" ("datetime") values (?))")); - qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)); QVERIFY(qtQuery.exec()); @@ -238,7 +239,8 @@ insert_Qt_QDateTime_UtcTimezone_DatetimeColumn() const /* QSQLITE driver returns a string of a datetime with a timezone that was sent to the database in unchanged form. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -383,7 +385,7 @@ insert_Qt_QDateTime_UtcTimezone_TimestampColumn() const QVERIFY(qtQuery.prepare(R"(insert into "datetimes" ("timestamp") values (?))")); - qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, Qt::UTC)); + qtQuery.addBindValue(QDateTime({2022, 8, 29}, {13, 14, 15}, TTimeZone::UTC)); /* QSQLITE driver takes the QDateTime timezone into account, it internally calls .toString(Qt::ISODateWithMs). */ @@ -424,7 +426,8 @@ insert_Qt_QDateTime_UtcTimezone_TimestampColumn() const /* QSQLITE driver returns a string of a datetime with a timezone that was sent to the database in unchanged form. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 29}, {13, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 29}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -568,7 +571,7 @@ insert_QDateTime_UtcTimezone_DatetimeColumn_OnReturnQDateTime() const // Insert quint64 lastId = createQuery()->from(*datetimes).insertGetId( {{*datetime, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -584,7 +587,8 @@ insert_QDateTime_UtcTimezone_DatetimeColumn_OnReturnQDateTime() const // TinyORM QueryBuilder fixes this and returns the QDateTime instead of QString const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -617,7 +621,8 @@ insert_QDateTime_0200Timezone_DatetimeColumn_OnReturnQDateTime() const // TinyORM QueryBuilder fixes this and returns the QDateTime instead of QString const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -648,7 +653,8 @@ void tst_SQLite_QDateTime::insert_QString_DatetimeColumn_OnReturnQDateTime() con // TinyORM QueryBuilder fixes this and returns the QDateTime instead of QString const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -665,7 +671,7 @@ insert_QDateTime_UtcTimezone_TimestampColumn_OnReturnQDateTime() const // Insert quint64 lastId = createQuery()->from(*datetimes).insertGetId( {{*timestamp, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -681,7 +687,8 @@ insert_QDateTime_UtcTimezone_TimestampColumn_OnReturnQDateTime() const // TinyORM QueryBuilder fixes this and returns the QDateTime instead of QString const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -714,7 +721,8 @@ insert_QDateTime_0200Timezone_TimestampColumn_OnReturnQDateTime() const // TinyORM QueryBuilder fixes this and returns the QDateTime instead of QString const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -745,7 +753,8 @@ void tst_SQLite_QDateTime::insert_QString_TimestampColumn_OnReturnQDateTime() co // TinyORM QueryBuilder fixes this and returns the QDateTime instead of QString const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -766,7 +775,7 @@ insert_QDateTime_UtcTimezone_DatetimeColumn_OffReturnQDateTime() const // Insert quint64 lastId = createQuery()->from(*datetimes).insertGetId( {{*datetime, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -875,7 +884,7 @@ insert_QDateTime_UtcTimezone_TimestampColumn_OffReturnQDateTime() const // Insert quint64 lastId = createQuery()->from(*datetimes).insertGetId( {{*timestamp, - QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC)}}); + QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC)}}); // Verify { @@ -1780,12 +1789,8 @@ insert_QDateTime_0300Timezone_DatetimeColumn_UtcOnServer_DontConvert() const // Restore restore(lastId); - DB::connection(m_connection) - .setQtTimeZone(QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, - QVariant::fromValue(Qt::UTC)}); - QCOMPARE(DB::qtTimeZone(m_connection), - (QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, - QVariant::fromValue(Qt::UTC)})); + DB::connection(m_connection).setQtTimeZone(QtTimeZoneConfig::utc()); + QCOMPARE(DB::qtTimeZone(m_connection), QtTimeZoneConfig::utc()); } // NOLINTEND(readability-convert-member-functions-to-static) diff --git a/tests/auto/functional/orm/tiny/castattributes/tst_castattributes.cpp b/tests/auto/functional/orm/tiny/castattributes/tst_castattributes.cpp index c34edca8d..b561cda63 100644 --- a/tests/auto/functional/orm/tiny/castattributes/tst_castattributes.cpp +++ b/tests/auto/functional/orm/tiny/castattributes/tst_castattributes.cpp @@ -22,6 +22,7 @@ using Orm::DB; using Orm::Exceptions::InvalidArgumentError; using Orm::Exceptions::InvalidFormatError; using Orm::SQLiteConnection; +using Orm::TTimeZone; using Orm::Tiny::CastItem; using Orm::Tiny::CastType; @@ -1008,7 +1009,7 @@ void tst_CastAttributes::defaultCast_timestamp() const auto datetimeActual = attribute.value(); - QCOMPARE(datetimeActual, QDateTime({2022, 9, 9}, {8, 41, 28}, Qt::UTC)); + QCOMPARE(datetimeActual, QDateTime({2022, 9, 9}, {8, 41, 28}, TTimeZone::UTC)); QCOMPARE(datetimeActual.timeZone(), QTimeZone::utc()); } @@ -1025,7 +1026,7 @@ void tst_CastAttributes::defaultCast_datetime() const auto timestampActual = attribute.value(); - QCOMPARE(timestampActual, QDateTime({2022, 9, 10}, {8, 41, 28}, Qt::UTC)); + QCOMPARE(timestampActual, QDateTime({2022, 9, 10}, {8, 41, 28}, TTimeZone::UTC)); QCOMPARE(timestampActual.timeZone(), QTimeZone::utc()); } @@ -2452,7 +2453,7 @@ void tst_CastAttributes::cast_timestamp_to_QDateTime() const Q_UNREACHABLE(); QCOMPARE(attribute.value(), - QDateTime({2022, 9, 9}, {8, 41, 28}, Qt::UTC)); + QDateTime({2022, 9, 9}, {8, 41, 28}, TTimeZone::UTC)); } void tst_CastAttributes::cast_timestamp_to_QString() const @@ -2509,8 +2510,8 @@ void tst_CastAttributes::cast_timestamp_to_Timestamp() const QCOMPARE(attribute.value(), static_cast(1662712888)); // This is not 100% ok, but I want to do also this QCOMPARE() - QCOMPARE(QDateTime::fromSecsSinceEpoch(attribute.value(), Qt::UTC), - QDateTime({2022, 9, 9}, {8, 41, 28}, Qt::UTC)); + QCOMPARE(QDateTime::fromSecsSinceEpoch(attribute.value(), TTimeZone::UTC), + QDateTime({2022, 9, 9}, {8, 41, 28}, TTimeZone::UTC)); } void tst_CastAttributes::cast_datetime_to_QDateTime() const @@ -2536,7 +2537,7 @@ void tst_CastAttributes::cast_datetime_to_QDateTime() const Q_UNREACHABLE(); QCOMPARE(attribute.value(), - QDateTime({2022, 9, 10}, {8, 41, 28}, Qt::UTC)); + QDateTime({2022, 9, 10}, {8, 41, 28}, TTimeZone::UTC)); } void tst_CastAttributes::cast_datetime_to_QString() const diff --git a/tests/auto/functional/orm/tiny/model/tst_model.cpp b/tests/auto/functional/orm/tiny/model/tst_model.cpp index e96f77881..b98d6bdc5 100644 --- a/tests/auto/functional/orm/tiny/model/tst_model.cpp +++ b/tests/auto/functional/orm/tiny/model/tst_model.cpp @@ -28,6 +28,7 @@ using Orm::Constants::SIZE_; using Orm::Constants::UPDATED_AT; using Orm::DB; +using Orm::TTimeZone; using Orm::Tiny::ConnectionOverride; using Orm::Tiny::Exceptions::ModelNotFoundError; using Orm::Tiny::Model; @@ -169,7 +170,7 @@ void tst_Model::save_Insert() const Torrent torrent; - const auto addedOn = QDateTime({2020, 10, 1}, {20, 22, 10}, Qt::UTC); + const auto addedOn = QDateTime({2020, 10, 1}, {20, 22, 10}, TTimeZone::UTC); torrent.setAttribute(NAME, "test50") .setAttribute(SIZE_, 50) .setAttribute(Progress, 50) @@ -222,7 +223,7 @@ void tst_Model::save_Insert_WithDefaultValues() const Torrent torrent; - const auto addedOn = QDateTime({2020, 10, 1}, {20, 22, 10}, Qt::UTC); + const auto addedOn = QDateTime({2020, 10, 1}, {20, 22, 10}, TTimeZone::UTC); torrent.setAttribute(NAME, "test51") .setAttribute("added_on", addedOn) .setAttribute(HASH_, "5179e3af2768cdf52ec84c1f320333f68401dc61"); @@ -624,8 +625,8 @@ void tst_Model::whereEq() const } // QDateTime { - auto torrent = Torrent::whereEq("added_on", - QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC)) + auto torrent = Torrent::whereEq("added_on", QDateTime({2020, 8, 1}, {20, 11, 10}, + TTimeZone::UTC)) ->first(); QVERIFY(torrent); QCOMPARE(torrent->getKey(), QVariant(1)); @@ -1173,7 +1174,7 @@ void tst_Model::firstOrCreate_Found() const QCOMPARE(torrent[SIZE_], QVariant(13)); QCOMPARE(torrent[Progress], QVariant(300)); QCOMPARE(torrent["added_on"], - QVariant(QDateTime({2020, 8, 3}, {20, 11, 10}, Qt::UTC))); + QVariant(QDateTime({2020, 8, 3}, {20, 11, 10}, TTimeZone::UTC))); QCOMPARE(torrent[HASH_], QVariant("3579e3af2768cdf52ec84c1f320333f68401dc6e")); } } @@ -1184,7 +1185,7 @@ void tst_Model::firstOrCreate_NotFound() const ConnectionOverride::connection = connection; - const auto addedOn = QDateTime({2020, 10, 1}, {20, 22, 10}, Qt::UTC); + const auto addedOn = QDateTime({2020, 10, 1}, {20, 22, 10}, TTimeZone::UTC); auto torrent = Torrent::firstOrCreate( {{NAME, "test100"}}, @@ -1306,7 +1307,7 @@ void tst_Model::create() const ConnectionOverride::connection = connection; - const auto addedOn = QDateTime({2021, 2, 1}, {20, 22, 10}, Qt::UTC); + const auto addedOn = QDateTime({2021, 2, 1}, {20, 22, 10}, TTimeZone::UTC); auto torrent = Torrent::create({ {NAME, "test100"}, @@ -1347,7 +1348,7 @@ void tst_Model::create_Failed() const ConnectionOverride::connection = connection; - const auto addedOn = QDateTime({2021, 2, 1}, {20, 22, 10}, Qt::UTC); + const auto addedOn = QDateTime({2021, 2, 1}, {20, 22, 10}, TTimeZone::UTC); Torrent torrent; TVERIFY_THROWS_EXCEPTION(QueryError, @@ -1388,7 +1389,7 @@ void tst_Model::incrementAndDecrement() const QCOMPARE(sizeOriginal, QVariant(14)); QCOMPARE(progressOriginal, QVariant(400)); QCOMPARE(updatedAtOriginal, - QVariant(QDateTime({2021, 1, 4}, {18, 46, 31}, Qt::UTC))); + QVariant(QDateTime({2021, 1, 4}, {18, 46, 31}, TTimeZone::UTC))); // Increment torrent4_1->increment(SIZE_, 2, {{Progress, 444}}); @@ -1473,7 +1474,7 @@ void tst_Model::update() const QVERIFY(torrent->exists); QCOMPARE(progressOriginal, QVariant(400)); QCOMPARE(updatedAtOriginal, - QVariant(QDateTime({2021, 1, 4}, {18, 46, 31}, Qt::UTC))); + QVariant(QDateTime({2021, 1, 4}, {18, 46, 31}, TTimeZone::UTC))); auto result = torrent->update({{Progress, 449}}); @@ -1728,7 +1729,7 @@ void tst_Model::touch_WithAttribute() const // Verify an original added_on value auto addedOnOriginal = Torrent::find(1)->getAttribute("added_on"); QCOMPARE(addedOnOriginal, - QVariant(QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC))); + QVariant(QDateTime({2020, 8, 1}, {20, 11, 10}, TTimeZone::UTC))); // Save a time before touch auto timeBeforeTouch = QDateTime::currentDateTimeUtc(); @@ -1832,7 +1833,7 @@ void tst_Model::getAttribute_UnixTimestamp_With_UDates() const QCOMPARE(Helpers::qVariantTypeId(addedOn), QMetaType::QDateTime); // This is most important, should return QDateTime and not int QCOMPARE(addedOn.value(), - QDateTime::fromSecsSinceEpoch(1659361016, Qt::UTC)); + QDateTime::fromSecsSinceEpoch(1659361016, TTimeZone::UTC)); } void tst_Model::getAttribute_UnixTimestamp_WithOut_UDates() const diff --git a/tests/auto/functional/orm/tiny/model_appends/tst_model_appends.cpp b/tests/auto/functional/orm/tiny/model_appends/tst_model_appends.cpp index e279ef8b9..18dfcadcb 100644 --- a/tests/auto/functional/orm/tiny/model_appends/tst_model_appends.cpp +++ b/tests/auto/functional/orm/tiny/model_appends/tst_model_appends.cpp @@ -16,6 +16,7 @@ using Orm::Constants::Progress; using Orm::Constants::SIZE_; using Orm::Constants::UPDATED_AT; +using Orm::TTimeZone; using Orm::Utils::NullVariant; using TypeUtils = Orm::Utils::Type; @@ -484,8 +485,8 @@ void tst_Model_Appends::toVector_WithAppends_WithHidden_ForExistingAttribute() c void tst_Model_Appends::toMap_WithAppends_OverrideSerializeDateTime() const { auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"time", sl("14:11:15")}, }); @@ -515,8 +516,8 @@ void tst_Model_Appends::toVector_WithAppends_OverrideSerializeDateTime() const { auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"time", QTime(14, 11, 15)}, // It must also accept QTime() instances }); diff --git a/tests/auto/functional/orm/tiny/model_conn_indep/tst_model_connection_independent.cpp b/tests/auto/functional/orm/tiny/model_conn_indep/tst_model_connection_independent.cpp index a2d04954c..fcbfaafdb 100644 --- a/tests/auto/functional/orm/tiny/model_conn_indep/tst_model_connection_independent.cpp +++ b/tests/auto/functional/orm/tiny/model_conn_indep/tst_model_connection_independent.cpp @@ -27,6 +27,7 @@ using Orm::Exceptions::InvalidArgumentError; using Orm::Exceptions::MultipleRecordsFoundError; using Orm::Exceptions::RecordsNotFoundError; using Orm::One; +using Orm::TTimeZone; using TypeUtils = Orm::Utils::Type; @@ -245,7 +246,7 @@ defaultAttributeValues_WithQDateTime_InstanceMethod() const QCOMPARE(torrent[SIZE_], QVariant(0)); QCOMPARE(torrent[Progress], QVariant(0)); QCOMPARE(torrent["added_on"], - QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, Qt::UTC))); + QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, TTimeZone::UTC))); QCOMPARE(torrent.getAttributes().size(), 3); // Check also the connection name @@ -268,7 +269,7 @@ defaultAttributeValues_WithQDateTime_InstanceAttributesMethod() const QCOMPARE(torrent[SIZE_], QVariant(0)); QCOMPARE(torrent[Progress], QVariant(0)); QCOMPARE(torrent["added_on"], - QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, Qt::UTC))); + QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, TTimeZone::UTC))); QCOMPARE(torrent[NAME], QVariant(name)); QCOMPARE(torrent[NOTE], QVariant(note)); QCOMPARE(torrent.getAttributes().size(), 5); @@ -291,7 +292,7 @@ defaultAttributeValues_WithQDateTime_InstanceMethod_WithConnection() const QCOMPARE(torrent[SIZE_], QVariant(0)); QCOMPARE(torrent[Progress], QVariant(0)); QCOMPARE(torrent["added_on"], - QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, Qt::UTC))); + QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, TTimeZone::UTC))); QCOMPARE(torrent.getAttributes().size(), 3); // Check also the connection name @@ -324,7 +325,7 @@ defaultAttributeValues_WithQDateTime_InstanceAttributesMethod_WithConnection() c QCOMPARE(torrent[SIZE_], QVariant(0)); QCOMPARE(torrent[Progress], QVariant(0)); QCOMPARE(torrent["added_on"], - QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, Qt::UTC))); + QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, TTimeZone::UTC))); QCOMPARE(torrent[NAME], QVariant(name)); QCOMPARE(torrent[NOTE], QVariant(note)); QCOMPARE(torrent.getAttributes().size(), 5); @@ -409,7 +410,7 @@ defaultAttributeValues_WithQDateTime_InstanceHeapMethod() const QCOMPARE((*torrent)[SIZE_], QVariant(0)); QCOMPARE((*torrent)[Progress], QVariant(0)); QCOMPARE((*torrent)["added_on"], - QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, Qt::UTC))); + QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, TTimeZone::UTC))); QCOMPARE((*torrent).getAttributes().size(), 3); // Check also the connection name @@ -432,7 +433,7 @@ defaultAttributeValues_WithQDateTime_InstanceHeapAttributesMethod() const QCOMPARE((*torrent)[SIZE_], QVariant(0)); QCOMPARE((*torrent)[Progress], QVariant(0)); QCOMPARE((*torrent)["added_on"], - QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, Qt::UTC))); + QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, TTimeZone::UTC))); QCOMPARE((*torrent)[NAME], QVariant(name)); QCOMPARE((*torrent)[NOTE], QVariant(note)); QCOMPARE(torrent->getAttributes().size(), 5); @@ -455,7 +456,7 @@ defaultAttributeValues_WithQDateTime_InstanceHeapMethod_WithConnection() const QCOMPARE((*torrent)[SIZE_], QVariant(0)); QCOMPARE((*torrent)[Progress], QVariant(0)); QCOMPARE((*torrent)["added_on"], - QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, Qt::UTC))); + QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, TTimeZone::UTC))); QCOMPARE(torrent->getAttributes().size(), 3); // Check also the connection name @@ -488,7 +489,7 @@ defaultAttributeValues_WithQDateTime_InstanceHeapAttributesMethod_WithConnection QCOMPARE((*torrent)[SIZE_], QVariant(0)); QCOMPARE((*torrent)[Progress], QVariant(0)); QCOMPARE((*torrent)["added_on"], - QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, Qt::UTC))); + QVariant(QDateTime({2021, 4, 1}, {15, 10, 10}, TTimeZone::UTC))); QCOMPARE((*torrent)[NAME], QVariant(name)); QCOMPARE((*torrent)[NOTE], QVariant(note)); QCOMPARE(torrent->getAttributes().size(), 5); @@ -625,7 +626,7 @@ void tst_Model_Connection_Independent::subscriptOperator() const QCOMPARE((*torrent)[NAME], QVariant("test2")); QCOMPARE((*torrent)["added_on"], - QVariant(QDateTime({2020, 8, 2}, {20, 11, 10}, Qt::UTC))); + QVariant(QDateTime({2020, 8, 2}, {20, 11, 10}, TTimeZone::UTC))); } void tst_Model_Connection_Independent::subscriptOperator_OnLhs() const @@ -996,7 +997,7 @@ void tst_Model_Connection_Independent:: { Torrent_GuardedAttribute torrent; - const auto createdAt = QDateTime({2021, 2, 2}, {10, 11, 12}, Qt::UTC); + const auto createdAt = QDateTime({2021, 2, 2}, {10, 11, 12}, TTimeZone::UTC); torrent.forceFill({{CREATED_AT, createdAt}}); @@ -1192,13 +1193,13 @@ void tst_Model_Connection_Independent::pluck_With_u_dates() const auto result = Torrent::pluck("added_on"); QVector expected { - QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 2}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 3}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 4}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 5}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 6}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 7}, {20, 11, 10}, Qt::UTC), + QDateTime({2020, 8, 1}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 2}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 3}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 4}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 5}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 6}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 7}, {20, 11, 10}, TTimeZone::UTC), }; QCOMPARE(result, expected); } @@ -1207,13 +1208,13 @@ void tst_Model_Connection_Independent::pluck_With_u_dates() const auto result = Torrent::pluck("added_on", ID); std::map expected { - {1, QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC)}, - {2, QDateTime({2020, 8, 2}, {20, 11, 10}, Qt::UTC)}, - {3, QDateTime({2020, 8, 3}, {20, 11, 10}, Qt::UTC)}, - {4, QDateTime({2020, 8, 4}, {20, 11, 10}, Qt::UTC)}, - {5, QDateTime({2020, 8, 5}, {20, 11, 10}, Qt::UTC)}, - {6, QDateTime({2020, 8, 6}, {20, 11, 10}, Qt::UTC)}, - {7, QDateTime({2020, 8, 7}, {20, 11, 10}, Qt::UTC)}, + {1, QDateTime({2020, 8, 1}, {20, 11, 10}, TTimeZone::UTC)}, + {2, QDateTime({2020, 8, 2}, {20, 11, 10}, TTimeZone::UTC)}, + {3, QDateTime({2020, 8, 3}, {20, 11, 10}, TTimeZone::UTC)}, + {4, QDateTime({2020, 8, 4}, {20, 11, 10}, TTimeZone::UTC)}, + {5, QDateTime({2020, 8, 5}, {20, 11, 10}, TTimeZone::UTC)}, + {6, QDateTime({2020, 8, 6}, {20, 11, 10}, TTimeZone::UTC)}, + {7, QDateTime({2020, 8, 7}, {20, 11, 10}, TTimeZone::UTC)}, }; QCOMPARE(result, expected); } @@ -1222,13 +1223,13 @@ void tst_Model_Connection_Independent::pluck_With_u_dates() const auto result = Torrent::pluck(ID, "added_on"); std::map expected { - {QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC), 1}, - {QDateTime({2020, 8, 2}, {20, 11, 10}, Qt::UTC), 2}, - {QDateTime({2020, 8, 3}, {20, 11, 10}, Qt::UTC), 3}, - {QDateTime({2020, 8, 4}, {20, 11, 10}, Qt::UTC), 4}, - {QDateTime({2020, 8, 5}, {20, 11, 10}, Qt::UTC), 5}, - {QDateTime({2020, 8, 6}, {20, 11, 10}, Qt::UTC), 6}, - {QDateTime({2020, 8, 7}, {20, 11, 10}, Qt::UTC), 7}, + {QDateTime({2020, 8, 1}, {20, 11, 10}, TTimeZone::UTC), 1}, + {QDateTime({2020, 8, 2}, {20, 11, 10}, TTimeZone::UTC), 2}, + {QDateTime({2020, 8, 3}, {20, 11, 10}, TTimeZone::UTC), 3}, + {QDateTime({2020, 8, 4}, {20, 11, 10}, TTimeZone::UTC), 4}, + {QDateTime({2020, 8, 5}, {20, 11, 10}, TTimeZone::UTC), 5}, + {QDateTime({2020, 8, 6}, {20, 11, 10}, TTimeZone::UTC), 6}, + {QDateTime({2020, 8, 7}, {20, 11, 10}, TTimeZone::UTC), 7}, }; QCOMPARE(result, expected); } @@ -1257,13 +1258,13 @@ void tst_Model_Connection_Independent::pluck_QualifiedColumnOrKey_With_u_dates() auto result = Torrent::pluck("torrents.added_on"); QVector expected { - QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 2}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 3}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 4}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 5}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 6}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 7}, {20, 11, 10}, Qt::UTC), + QDateTime({2020, 8, 1}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 2}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 3}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 4}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 5}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 6}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 7}, {20, 11, 10}, TTimeZone::UTC), }; QCOMPARE(result, expected); } @@ -1272,13 +1273,13 @@ void tst_Model_Connection_Independent::pluck_QualifiedColumnOrKey_With_u_dates() auto result = Torrent::pluck("torrents.added_on", ID); std::map expected { - {1, QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC)}, - {2, QDateTime({2020, 8, 2}, {20, 11, 10}, Qt::UTC)}, - {3, QDateTime({2020, 8, 3}, {20, 11, 10}, Qt::UTC)}, - {4, QDateTime({2020, 8, 4}, {20, 11, 10}, Qt::UTC)}, - {5, QDateTime({2020, 8, 5}, {20, 11, 10}, Qt::UTC)}, - {6, QDateTime({2020, 8, 6}, {20, 11, 10}, Qt::UTC)}, - {7, QDateTime({2020, 8, 7}, {20, 11, 10}, Qt::UTC)}, + {1, QDateTime({2020, 8, 1}, {20, 11, 10}, TTimeZone::UTC)}, + {2, QDateTime({2020, 8, 2}, {20, 11, 10}, TTimeZone::UTC)}, + {3, QDateTime({2020, 8, 3}, {20, 11, 10}, TTimeZone::UTC)}, + {4, QDateTime({2020, 8, 4}, {20, 11, 10}, TTimeZone::UTC)}, + {5, QDateTime({2020, 8, 5}, {20, 11, 10}, TTimeZone::UTC)}, + {6, QDateTime({2020, 8, 6}, {20, 11, 10}, TTimeZone::UTC)}, + {7, QDateTime({2020, 8, 7}, {20, 11, 10}, TTimeZone::UTC)}, }; QCOMPARE(result, expected); } @@ -1287,13 +1288,13 @@ void tst_Model_Connection_Independent::pluck_QualifiedColumnOrKey_With_u_dates() auto result = Torrent::orderBy(ID)->pluck("added_on as added_on_alt"); QVector expected { - QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 2}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 3}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 4}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 5}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 6}, {20, 11, 10}, Qt::UTC), - QDateTime({2020, 8, 7}, {20, 11, 10}, Qt::UTC), + QDateTime({2020, 8, 1}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 2}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 3}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 4}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 5}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 6}, {20, 11, 10}, TTimeZone::UTC), + QDateTime({2020, 8, 7}, {20, 11, 10}, TTimeZone::UTC), }; QCOMPARE(result, expected); } @@ -1302,13 +1303,13 @@ void tst_Model_Connection_Independent::pluck_QualifiedColumnOrKey_With_u_dates() auto result = Torrent::pluck("added_on as added_on_alt", "id as id_alt"); std::map expected { - {1, QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC)}, - {2, QDateTime({2020, 8, 2}, {20, 11, 10}, Qt::UTC)}, - {3, QDateTime({2020, 8, 3}, {20, 11, 10}, Qt::UTC)}, - {4, QDateTime({2020, 8, 4}, {20, 11, 10}, Qt::UTC)}, - {5, QDateTime({2020, 8, 5}, {20, 11, 10}, Qt::UTC)}, - {6, QDateTime({2020, 8, 6}, {20, 11, 10}, Qt::UTC)}, - {7, QDateTime({2020, 8, 7}, {20, 11, 10}, Qt::UTC)}, + {1, QDateTime({2020, 8, 1}, {20, 11, 10}, TTimeZone::UTC)}, + {2, QDateTime({2020, 8, 2}, {20, 11, 10}, TTimeZone::UTC)}, + {3, QDateTime({2020, 8, 3}, {20, 11, 10}, TTimeZone::UTC)}, + {4, QDateTime({2020, 8, 4}, {20, 11, 10}, TTimeZone::UTC)}, + {5, QDateTime({2020, 8, 5}, {20, 11, 10}, TTimeZone::UTC)}, + {6, QDateTime({2020, 8, 6}, {20, 11, 10}, TTimeZone::UTC)}, + {7, QDateTime({2020, 8, 7}, {20, 11, 10}, TTimeZone::UTC)}, }; QCOMPARE(result, expected); } @@ -1317,13 +1318,13 @@ void tst_Model_Connection_Independent::pluck_QualifiedColumnOrKey_With_u_dates() auto result = Torrent::pluck("torrents.added_on", "id as id_alt"); std::map expected { - {1, QDateTime({2020, 8, 1}, {20, 11, 10}, Qt::UTC)}, - {2, QDateTime({2020, 8, 2}, {20, 11, 10}, Qt::UTC)}, - {3, QDateTime({2020, 8, 3}, {20, 11, 10}, Qt::UTC)}, - {4, QDateTime({2020, 8, 4}, {20, 11, 10}, Qt::UTC)}, - {5, QDateTime({2020, 8, 5}, {20, 11, 10}, Qt::UTC)}, - {6, QDateTime({2020, 8, 6}, {20, 11, 10}, Qt::UTC)}, - {7, QDateTime({2020, 8, 7}, {20, 11, 10}, Qt::UTC)}, + {1, QDateTime({2020, 8, 1}, {20, 11, 10}, TTimeZone::UTC)}, + {2, QDateTime({2020, 8, 2}, {20, 11, 10}, TTimeZone::UTC)}, + {3, QDateTime({2020, 8, 3}, {20, 11, 10}, TTimeZone::UTC)}, + {4, QDateTime({2020, 8, 4}, {20, 11, 10}, TTimeZone::UTC)}, + {5, QDateTime({2020, 8, 5}, {20, 11, 10}, TTimeZone::UTC)}, + {6, QDateTime({2020, 8, 6}, {20, 11, 10}, TTimeZone::UTC)}, + {7, QDateTime({2020, 8, 7}, {20, 11, 10}, TTimeZone::UTC)}, }; QCOMPARE(result, expected); } @@ -1353,7 +1354,7 @@ void tst_Model_Connection_Independent::only() const {ID, 1}, {NAME, QString("test1")}, {SIZE_, 11}, - {CREATED_AT, QDateTime({2016, 6, 1}, {8, 8, 23}, Qt::UTC)}, + {CREATED_AT, QDateTime({2016, 6, 1}, {8, 8, 23}, TTimeZone::UTC)}, }; QCOMPARE(attributes, expectedAttributes); } diff --git a/tests/auto/functional/orm/tiny/model_qdatetime/tst_model_qdatetime.cpp b/tests/auto/functional/orm/tiny/model_qdatetime/tst_model_qdatetime.cpp index db6bcaf9a..ac9541d2b 100644 --- a/tests/auto/functional/orm/tiny/model_qdatetime/tst_model_qdatetime.cpp +++ b/tests/auto/functional/orm/tiny/model_qdatetime/tst_model_qdatetime.cpp @@ -24,6 +24,7 @@ using Orm::Constants::UTC; using Orm::DB; using Orm::QtTimeZoneConfig; using Orm::QtTimeZoneType; +using Orm::TTimeZone; using Orm::Utils::NullVariant; using Orm::Tiny::ConnectionOverride; @@ -152,7 +153,7 @@ create_QDateTime_UtcTimezone_DatetimeAttribute_UtcOnServer() const // Insert { Datetime datetime; - datetime[*datetime_] = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + datetime[*datetime_] = QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC); // Check whether a stored value and type are correct const auto attribute = datetime.getAttributeFromArray(*datetime_); @@ -182,7 +183,8 @@ create_QDateTime_UtcTimezone_DatetimeAttribute_UtcOnServer() const configuration, TinyORM TinyBuilder fixes and unifies the buggy time zone behavior of all QtSql drivers. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -236,7 +238,8 @@ create_QDateTime_0200Timezone_DatetimeAttribute_UtcOnServer() const configuration, TinyORM TinyBuilder fixes and unifies the buggy time zone behavior of all QtSql drivers. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -288,7 +291,8 @@ void tst_Model_QDateTime::create_QString_DatetimeAttribute_UtcOnServer() const configuration, TinyORM TinyBuilder fixes and unifies the buggy time zone behavior of all QtSql drivers. */ const auto datetimeActual = datetimeDbVariant.value(); - const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto datetimeExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(datetimeActual, datetimeExpected); QCOMPARE(datetimeActual, datetimeExpected.toLocalTime()); @@ -311,7 +315,7 @@ create_QDateTime_UtcTimezone_TimestampAttribute_UtcOnServer() const // Insert { Datetime datetime; - datetime[*timestamp] = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + datetime[*timestamp] = QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC); // Check whether a stored value and type are correct const auto attribute = datetime.getAttributeFromArray(*timestamp); @@ -341,7 +345,8 @@ create_QDateTime_UtcTimezone_TimestampAttribute_UtcOnServer() const configuration, TinyORM TinyBuilder fixes and unifies the buggy time zone behavior of all QtSql drivers. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -395,7 +400,8 @@ create_QDateTime_0200Timezone_TimestampAttribute_UtcOnServer() const configuration, TinyORM TinyBuilder fixes and unifies the buggy time zone behavior of all QtSql drivers. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {11, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -447,7 +453,8 @@ void tst_Model_QDateTime::create_QString_TimestampAttribute_UtcOnServer() const configuration, TinyORM TinyBuilder fixes and unifies the buggy time zone behavior of all QtSql drivers. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + const auto timestampExpected = QDateTime({2022, 8, 28}, {13, 14, 15}, + TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -478,7 +485,7 @@ create_QDateTime_UtcTimezone_DatetimeAttribute_0200OnServer() const // Insert { Datetime datetime; - datetime[*datetime_] = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + datetime[*datetime_] = QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC); // Check whether a stored value and type are correct const auto attribute = datetime.getAttributeFromArray(*datetime_); @@ -655,7 +662,7 @@ create_QDateTime_UtcTimezone_TimestampAttribute_0200OnServer() const // Insert { Datetime datetime; - datetime[*timestamp] = QDateTime({2022, 8, 28}, {13, 14, 15}, Qt::UTC); + datetime[*timestamp] = QDateTime({2022, 8, 28}, {13, 14, 15}, TTimeZone::UTC); // Check whether a stored value and type are correct const auto attribute = datetime.getAttributeFromArray(*timestamp); @@ -1320,7 +1327,8 @@ create_QDateTime_0300Timezone_DatetimeAttribute_UtcOnServer_DontConvert() const This is the reason why we must use #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) everywhere for QtSql QMYSQL and QPSQL and tinymysql_lib_utc_qdatetime >= 20240618 for TinyDrivers TinyMySql. */ -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) if (const auto driverName = DB::driverName(connection); driverName == QMYSQL || driverName == QPSQL ) { @@ -1351,11 +1359,8 @@ create_QDateTime_0300Timezone_DatetimeAttribute_UtcOnServer_DontConvert() const // Restore restore(lastId); - DB::setQtTimeZone(QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, - QVariant::fromValue(Qt::UTC)}, connection); - QCOMPARE(DB::qtTimeZone(connection), - (QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, - QVariant::fromValue(Qt::UTC)})); + DB::setQtTimeZone(QtTimeZoneConfig::utc(), connection); + QCOMPARE(DB::qtTimeZone(connection), QtTimeZoneConfig::utc()); } // NOLINTEND(readability-convert-member-functions-to-static) @@ -1363,9 +1368,7 @@ create_QDateTime_0300Timezone_DatetimeAttribute_UtcOnServer_DontConvert() const void tst_Model_QDateTime::setUtcTimezone(const QString &connection) { - setTimezone(utcTimezoneString(connection), - {QtTimeZoneType::QtTimeSpec, QVariant::fromValue(Qt::UTC)}, - connection); + setTimezone(utcTimezoneString(connection), QtTimeZoneConfig::utc(), connection); } const QString &tst_Model_QDateTime::utcTimezoneString(const QString &connection) diff --git a/tests/auto/functional/orm/tiny/model_relations/tst_model_relations.cpp b/tests/auto/functional/orm/tiny/model_relations/tst_model_relations.cpp index 0eb36219c..fe1f7c736 100644 --- a/tests/auto/functional/orm/tiny/model_relations/tst_model_relations.cpp +++ b/tests/auto/functional/orm/tiny/model_relations/tst_model_relations.cpp @@ -35,6 +35,7 @@ using Orm::Exceptions::RuntimeError; using Orm::One; using Orm::QtTimeZoneConfig; using Orm::QtTimeZoneType; +using Orm::TTimeZone; using Orm::Tiny::AttributeItem; using Orm::Tiny::ConnectionOverride; @@ -2970,7 +2971,7 @@ timezone_TimestampAttribute_UtcOnServer_OnCustomPivotModel_ManyToMany() const configuration, TinyORM TinyBuilder fixes and unifies the buggy time zone behavior of all QtSql drivers. */ const auto timestampActual = timestampDbVariant.value(); - const auto timestampExpected = QDateTime({2021, 2, 21}, {17, 31, 58}, Qt::UTC); + const auto timestampExpected = QDateTime({2021, 2, 21}, {17, 31, 58}, TTimeZone::UTC); QCOMPARE(timestampActual, timestampExpected); QCOMPARE(timestampActual, timestampExpected.toLocalTime()); @@ -3027,7 +3028,8 @@ timezone_TimestampAttribute_UtcOnServer_DontConvert_OnCustomPivot_MtM() const This is the reason why we must use #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) everywhere for QtSql QMYSQL and QPSQL and tinymysql_lib_utc_qdatetime >= 20240618 for TinyDrivers TinyMySql. */ -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || tinymysql_lib_utc_qdatetime >= 20240618 +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) || \ + (defined(tinymysql_lib_utc_qdatetime) && tinymysql_lib_utc_qdatetime >= 20240618) if (const auto driverName = DB::driverName(connection); driverName == QMYSQL || driverName == QPSQL ) { @@ -3055,11 +3057,8 @@ timezone_TimestampAttribute_UtcOnServer_DontConvert_OnCustomPivot_MtM() const #endif // Restore - DB::setQtTimeZone(QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, - QVariant::fromValue(Qt::UTC)}, connection); - QCOMPARE(DB::qtTimeZone(connection), - (QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, - QVariant::fromValue(Qt::UTC)})); + DB::setQtTimeZone(QtTimeZoneConfig::utc(), connection); + QCOMPARE(DB::qtTimeZone(connection), QtTimeZoneConfig::utc()); } // NOLINTEND(readability-convert-member-functions-to-static) diff --git a/tests/auto/functional/orm/tiny/model_serialization/tst_model_serialization.cpp b/tests/auto/functional/orm/tiny/model_serialization/tst_model_serialization.cpp index 0123901e3..fe2136418 100644 --- a/tests/auto/functional/orm/tiny/model_serialization/tst_model_serialization.cpp +++ b/tests/auto/functional/orm/tiny/model_serialization/tst_model_serialization.cpp @@ -21,6 +21,7 @@ using Orm::Constants::SIZE_; using Orm::Constants::UPDATED_AT; using Orm::Constants::pivot_; +using Orm::TTimeZone; using Orm::Utils::Helpers; using Orm::Utils::NullVariant; @@ -221,8 +222,8 @@ void tst_Model_Serialization::toVector() const void tst_Model_Serialization::toMap_WithCasts() const { auto datetime = Datetime::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"timestamp", static_cast(1662712888)}, }); @@ -248,8 +249,8 @@ void tst_Model_Serialization::toMap_WithCasts() const void tst_Model_Serialization::toVector_WithCasts() const { auto datetime = Datetime::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"timestamp", static_cast(1662712888)}, }); @@ -275,8 +276,8 @@ void tst_Model_Serialization::toVector_WithCasts() const void tst_Model_Serialization::toMap_UDatesOnly_QDateTime_For_date_column() const { auto datetime = Datetime::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, }); QVariantMap serialized = datetime.toMap(); @@ -294,8 +295,8 @@ void tst_Model_Serialization::toVector_UDatesOnly_QDateTime_For_date_column() const { auto datetime = Datetime::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, }); QVector serialized = datetime.toVector(); @@ -379,8 +380,8 @@ void tst_Model_Serialization::toMap_WithDateModfiers() const Datetime::u_timeFormat = sl("HH:mm:ss.zzz"); auto datetime = Datetime::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"time", QTime(14, 11, 15)}, // It must also accept QTime() instances {"time_ms", QTime(14, 11, 15, 123)}, // It must also accept QTime() instances }); @@ -412,8 +413,8 @@ void tst_Model_Serialization::toMap_WithDateModfiers() const void tst_Model_Serialization::toVector_WithDateModfiers() const { auto datetime = Datetime::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"time", sl("14:11:15")}, {"time_ms", sl("14:11:15.12")}, }); @@ -444,7 +445,7 @@ void tst_Model_Serialization::toVector_WithDateModfiers() const void tst_Model_Serialization::toMap_WithDateModfiers_UnixTimestamp() const { auto datetime = Datetime::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, }); datetime.mergeCasts({ @@ -467,7 +468,7 @@ void tst_Model_Serialization::toMap_WithDateModfiers_UnixTimestamp() const void tst_Model_Serialization::toVector_WithDateModfiers_UnixTimestamp() const { auto datetime = Datetime::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, }); datetime.mergeCasts({ @@ -490,8 +491,8 @@ void tst_Model_Serialization::toVector_WithDateModfiers_UnixTimestamp() const void tst_Model_Serialization::toMap_UDatesOnly_OverrideSerializeDateTime() const { auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, }); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -518,8 +519,8 @@ void tst_Model_Serialization::toVector_UDatesOnly_OverrideSerializeDateTime() const { auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, }); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -545,8 +546,8 @@ tst_Model_Serialization::toVector_UDatesOnly_OverrideSerializeDateTime() const void tst_Model_Serialization::toMap_CastsOnly_OverrideSerializeDateTime() const { auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"time", sl("14:11:15")}, {"time_ms", sl("14:11:15.123")}, }); @@ -582,8 +583,8 @@ tst_Model_Serialization::toVector_CastsOnly_OverrideSerializeDateTime() const Datetime_SerializeOverride::u_timeFormat = sl("HH:mm:ss.zzz"); auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"time", QTime(14, 11, 15)}, // It must also accept QTime() instances {"time_ms", QTime(14, 11, 15, 123)}, // It must also accept QTime() instances }); @@ -616,8 +617,8 @@ void tst_Model_Serialization:: toMap_WithUDatesAndCasts_OverrideSerializeDateTime() const { auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, }); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -650,8 +651,8 @@ void tst_Model_Serialization:: toVector_WithUDatesAndCasts_OverrideSerializeDateTime() const { auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, }); #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) @@ -688,8 +689,8 @@ void tst_Model_Serialization:: Datetime_SerializeOverride::u_timeFormat = sl("HH:mm:ss.zzz"); auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"time", QTime(14, 11, 15)}, // It must also accept QTime() instances {"time_ms", QTime(14, 11, 15, 12)}, // It must also accept QTime() instances }); @@ -728,8 +729,8 @@ void tst_Model_Serialization:: Datetime_SerializeOverride::u_timeFormat = sl("HH:mm:ss.zzz"); auto datetime = Datetime_SerializeOverride::instance({ - {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, Qt::UTC)}, - {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, Qt::UTC)}, + {"datetime", QDateTime({2023, 05, 13}, {10, 11, 12}, TTimeZone::UTC)}, + {"date", QDateTime({2023, 05, 14}, {10, 11, 12}, TTimeZone::UTC)}, {"time", sl("14:11:15")}, {"time_ms", sl("14:11:15.123")}, }); diff --git a/tests/auto/functional/orm/tiny/softdeletes/tst_softdeletes.cpp b/tests/auto/functional/orm/tiny/softdeletes/tst_softdeletes.cpp index 6a5dc4f57..2138df3d4 100644 --- a/tests/auto/functional/orm/tiny/softdeletes/tst_softdeletes.cpp +++ b/tests/auto/functional/orm/tiny/softdeletes/tst_softdeletes.cpp @@ -216,10 +216,12 @@ void tst_SoftDeletes::onlyTrashed() const namespace { - const auto UpdatedAt4Original = QDateTime({2022, 1, 4}, {17, 46, 31}, Qt::UTC); // clazy:exclude=non-pod-global-static - const auto DeletedAt4Original = QDateTime({2022, 1, 4}, {20, 46, 31}, Qt::UTC); // clazy:exclude=non-pod-global-static - const auto UpdatedAt5Original = QDateTime({2022, 1, 5}, {17, 46, 31}, Qt::UTC); // clazy:exclude=non-pod-global-static - const auto DeletedAt5Original = QDateTime({2022, 1, 5}, {20, 46, 31}, Qt::UTC); // clazy:exclude=non-pod-global-static + using Orm::TTimeZone; + + const auto UpdatedAt4Original = QDateTime({2022, 1, 4}, {17, 46, 31}, TTimeZone::UTC); // clazy:exclude=non-pod-global-static + const auto DeletedAt4Original = QDateTime({2022, 1, 4}, {20, 46, 31}, TTimeZone::UTC); // clazy:exclude=non-pod-global-static + const auto UpdatedAt5Original = QDateTime({2022, 1, 5}, {17, 46, 31}, TTimeZone::UTC); // clazy:exclude=non-pod-global-static + const auto DeletedAt5Original = QDateTime({2022, 1, 5}, {20, 46, 31}, TTimeZone::UTC); // clazy:exclude=non-pod-global-static } // namespace void tst_SoftDeletes::restore_remove_OnModel() const diff --git a/tests/auto/functional/orm/tiny/tinybuilder/tst_tinybuilder.cpp b/tests/auto/functional/orm/tiny/tinybuilder/tst_tinybuilder.cpp index 53d8316ee..d364e788d 100644 --- a/tests/auto/functional/orm/tiny/tinybuilder/tst_tinybuilder.cpp +++ b/tests/auto/functional/orm/tiny/tinybuilder/tst_tinybuilder.cpp @@ -11,6 +11,8 @@ using Orm::Constants::NAME; using Orm::Constants::Progress; using Orm::Constants::SIZE_; +using Orm::TTimeZone; + using Orm::Tiny::ConnectionOverride; using Orm::Tiny::Exceptions::ModelNotFoundError; @@ -194,7 +196,7 @@ void tst_TinyBuilder::incrementAndDecrement() const QCOMPARE(sizeOriginal, QVariant(14)); QCOMPARE(progressOriginal, QVariant(400)); QCOMPARE(updatedAtOriginal, - QVariant(QDateTime({2021, 1, 4}, {18, 46, 31}, Qt::UTC))); + QVariant(QDateTime({2021, 1, 4}, {18, 46, 31}, TTimeZone::UTC))); // Increment Torrent::whereEq(ID, 4)->increment(SIZE_, 2, {{Progress, 444}}); @@ -241,7 +243,7 @@ void tst_TinyBuilder::update() const QVERIFY(torrent->exists); QCOMPARE(progressOriginal, QVariant(400)); QCOMPARE(updatedAtOriginal, - QVariant(QDateTime({2021, 1, 4}, {18, 46, 31}, Qt::UTC))); + QVariant(QDateTime({2021, 1, 4}, {18, 46, 31}, TTimeZone::UTC))); auto [affected, query] = Torrent::whereEq(ID, 4)->update({{Progress, 447}}); QCOMPARE(affected, 1); diff --git a/tests/auto/unit/orm/databaseconnection/tst_databaseconnection.cpp b/tests/auto/unit/orm/databaseconnection/tst_databaseconnection.cpp index bb4856d22..2dc8d6b33 100644 --- a/tests/auto/unit/orm/databaseconnection/tst_databaseconnection.cpp +++ b/tests/auto/unit/orm/databaseconnection/tst_databaseconnection.cpp @@ -819,11 +819,10 @@ void tst_DatabaseConnection::timezone_And_qt_timezone() const // Original config. qt_timezone QCOMPARE(DB::originalConfigValue(qt_timezone, connection), - QVariant::fromValue(Qt::UTC)); + QVariant::fromValue(Orm::TTimeZone::UTC)); // Connection qt_timezone (parsed) - QCOMPARE(connectionRef.getQtTimeZone(), - (QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, Qt::UTC})); + QCOMPARE(connectionRef.getQtTimeZone(), QtTimeZoneConfig::utc()); // Time zone for the database connection (session variable) const auto timeZone = connectionRef.getConfig(timezone_); diff --git a/tests/auto/unit/orm/tiny/mysql_tinybuilder/tst_mysql_tinybuilder.cpp b/tests/auto/unit/orm/tiny/mysql_tinybuilder/tst_mysql_tinybuilder.cpp index 35b7ea640..e13171b46 100644 --- a/tests/auto/unit/orm/tiny/mysql_tinybuilder/tst_mysql_tinybuilder.cpp +++ b/tests/auto/unit/orm/tiny/mysql_tinybuilder/tst_mysql_tinybuilder.cpp @@ -21,6 +21,7 @@ using Orm::Exceptions::InvalidArgumentError; using Orm::QueryBuilder; using Orm::Tiny::Model; using Orm::Tiny::TinyBuilder; +using Orm::TTimeZone; using Orm::Utils::Helpers; using Orm::Utils::NullVariant; @@ -227,7 +228,8 @@ void tst_MySql_TinyBuilder::setAttribute_UnixTimestamp_With_UDates_UDateFormat() { Role role; role.setConnection(m_connection); - role.setAttribute("added_on", QDateTime::fromSecsSinceEpoch(timestamp, Qt::UTC)); + role.setAttribute("added_on", + QDateTime::fromSecsSinceEpoch(timestamp, TTimeZone::UTC)); const auto &attributes = role.getAttributes(); @@ -280,7 +282,7 @@ void tst_MySql_TinyBuilder:: Role_CustomUDate::u_dates = QStringList {"added_on"}; /* Expected format without u_dateFormat is - 2022-08-03 15:36:56 UTC, even if the input is the unix timestamp. */ - auto expectedTimestamp = QDateTime::fromSecsSinceEpoch(timestamp, Qt::UTC) + auto expectedTimestamp = QDateTime::fromSecsSinceEpoch(timestamp, TTimeZone::UTC) .toString(Role_CustomUDate() .setConnection(m_connection) .getDateFormat()); @@ -289,7 +291,8 @@ void tst_MySql_TinyBuilder:: { Role_CustomUDate role; role.setConnection(m_connection); - role.setAttribute("added_on", QDateTime::fromSecsSinceEpoch(timestamp, Qt::UTC)); + role.setAttribute("added_on", + QDateTime::fromSecsSinceEpoch(timestamp, TTimeZone::UTC)); const auto &attributes = role.getAttributes(); @@ -330,14 +333,15 @@ void tst_MySql_TinyBuilder::setAttribute_UnixTimestamp_WithOut_UDates() const { /* Expected format without u_dateFormat is - 2022-08-03 15:36:56 UTC, even if the input is the unix timestamp. */ - auto expectedTimestamp = QDateTime::fromSecsSinceEpoch(timestamp, Qt::UTC) + auto expectedTimestamp = QDateTime::fromSecsSinceEpoch(timestamp, TTimeZone::UTC) .toString(Role_CustomUDate() .setConnection(m_connection) .getDateFormat()); Role_CustomUDate role; role.setConnection(m_connection); - role.setAttribute("added_on", QDateTime::fromSecsSinceEpoch(timestamp, Qt::UTC)); + role.setAttribute("added_on", + QDateTime::fromSecsSinceEpoch(timestamp, TTimeZone::UTC)); const auto &attributes = role.getAttributes(); diff --git a/tests/models/models/torrenteager.hpp b/tests/models/models/torrenteager.hpp index 70bd8a4b0..d9ff728c5 100644 --- a/tests/models/models/torrenteager.hpp +++ b/tests/models/models/torrenteager.hpp @@ -59,7 +59,7 @@ class TorrentEager final : public Model u_attributes { // NOLINT(cppcoreguidelines-interfaces-global-init) {SIZE_, 0}, {Progress, 0}, - {"added_on", QDateTime({2021, 4, 1}, {15, 10, 10}, Qt::UTC)}, + {"added_on", QDateTime({2021, 4, 1}, {15, 10, 10}, Orm::TTimeZone::UTC)}, }; /*! The attributes that are mass assignable. */ diff --git a/tests/testdata_tom/main.cpp b/tests/testdata_tom/main.cpp index 9404db62f..a8443df11 100644 --- a/tests/testdata_tom/main.cpp +++ b/tests/testdata_tom/main.cpp @@ -28,6 +28,7 @@ using Orm::DatabaseManager; using Orm::DB; +using Orm::QtTimeZoneConfig; using ConfigUtils = Orm::Utils::Configuration; @@ -101,7 +102,7 @@ std::shared_ptr setupDatabaseManager() /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + {qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())}, {prefix_, EMPTY}, {prefix_indexes, false}, {strict_, true}, @@ -127,7 +128,7 @@ std::shared_ptr setupDatabaseManager() /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + {qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())}, {prefix_, EMPTY}, {prefix_indexes, false}, {strict_, true}, @@ -153,7 +154,7 @@ std::shared_ptr setupDatabaseManager() /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + {qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())}, {prefix_, EMPTY}, {prefix_indexes, false}, // {isolation_level, sl("REPEATABLE READ")}, // Postgres default is READ COMMITTED @@ -173,7 +174,7 @@ std::shared_ptr setupDatabaseManager() /* Specifies what time zone all QDateTime-s will have, the overridden default is the Qt::UTC, set to the Qt::LocalTime or QtTimeZoneType::DontConvert to use the system local time. */ - {qt_timezone, QVariant::fromValue(Qt::UTC)}, + {qt_timezone, QVariant::fromValue(QtTimeZoneConfig::utc())}, /* Return a QDateTime with the correct time zone instead of the QString, only works when the qt_timezone isn't set to the DontConvert. */ {return_qdatetime, true},