changed qt_timezone default to Qt::UTC

Previously, it was the QtTimeZoneType::DontConvert that implied the
Qt::LocalTime timezone spec.

Setting this to the Qt::UTC by default is the only way to have the
maximum level of interoperability between TinyORM and other libraries
and services.

 - updated comments in docs and source code
This commit is contained in:
silverqx
2023-06-29 12:07:42 +02:00
parent 969027b0a2
commit aad52a89c8
13 changed files with 91 additions and 42 deletions
+3 -1
View File
@@ -191,7 +191,9 @@ And paste the following code.
{charset_, qEnvironmentVariable("DB_MYSQL_CHARSET", UTF8MB4)},
{collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)},
{timezone_, TZ00},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
+24 -8
View File
@@ -74,7 +74,9 @@ You can create and configure a new database connection using the `create` method
{"charset", qEnvironmentVariable("DB_CHARSET", "utf8mb4")},
{"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_0900_ai_ci")},
{"timezone", "+00:00"},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{"prefix", ""},
{"prefix_indexes", false},
@@ -101,7 +103,9 @@ You can create and configure a new database connection using the `create` method
{"password", qEnvironmentVariable("DB_PASSWORD", "")},
{"charset", qEnvironmentVariable("DB_CHARSET", "utf8")},
{"timezone", "UTC"},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{"prefix", ""},
{"prefix_indexes", false},
@@ -121,7 +125,9 @@ You can create and configure a new database connection using the `create` method
{"database", qEnvironmentVariable("DB_DATABASE", "/example/example.sqlite3")},
{"foreign_key_constraints", qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},
{"check_database_exists", true},
// Specifies what time zone all QDateTime-s will have
/* 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)},
/* Return a QDateTime with the correct time zone instead of the QString,
only works when the qt_timezone isn't set to the DontConvert. */
@@ -148,7 +154,9 @@ You can create and configure a new database connection using the `create` method
{"charset", qEnvironmentVariable("DB_CHARSET", "utf8mb4")},
{"collation", qEnvironmentVariable("DB_COLLATION", "utf8mb4_unicode_520_ci")},
{"timezone", "+00:00"},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{"prefix", ""},
{"prefix_indexes", false},
@@ -188,7 +196,9 @@ You can create and configure a new database connection using the `create` method
// Or
// {options, ConfigUtils::mysqlSslOptions()},
{timezone_, TZ00},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -233,7 +243,9 @@ You can create and configure a new database connection using the `create` method
// Or
// {options_, ConfigUtils::postgresSslOptions()},
{timezone_, UTC},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -261,7 +273,9 @@ You can create and configure a new database connection using the `create` method
{database_, qEnvironmentVariable("DB_DATABASE", "C:/SQLite/example.sqlite3")},
{foreign_key_constraints, qEnvironmentVariable("DB_FOREIGN_KEYS", "true")},
{check_database_exists, true},
// Specifies what time zone all QDateTime-s will have
/* 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)},
/* Return a QDateTime with the correct time zone instead of the QString,
only works when the qt_timezone isn't set to the DontConvert. */
@@ -298,7 +312,9 @@ You can create and configure a new database connection using the `create` method
// Or
// {options, ConfigUtils::mariaSslOptions()},
{timezone_, TZ00},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
+12 -4
View File
@@ -82,7 +82,9 @@ std::shared_ptr<DatabaseManager> setupManager()
{collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)},
// SYSTEM - set the time zone to your local MySQL server time zone
{timezone_, TZ00},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -106,7 +108,9 @@ std::shared_ptr<DatabaseManager> setupManager()
UTF8MB4Unicode520ci)},
// SYSTEM - set the time zone to your local MySQL server time zone
{timezone_, TZ00},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -130,7 +134,9 @@ std::shared_ptr<DatabaseManager> setupManager()
{charset_, qEnvironmentVariable("DB_PGSQL_CHARSET", UTF8)},
// LOCAL/DEFAULT - set the time zone to your local PostgreSQL server time zone
{timezone_, UTC},
// Specifies what time zone all QDateTime-s will have
/* 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)},
// Examples of qt_timezone
// {qt_timezone, QVariant::fromValue(QTimeZone("Europe/Bratislava"))},
@@ -155,7 +161,9 @@ std::shared_ptr<DatabaseManager> setupManager()
{database_, qEnvironmentVariable("DB_SQLITE_DATABASE", {})},
{foreign_key_constraints, true},
{check_database_exists, true},
// Specifies what time zone all QDateTime-s will have
/* 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)},
/* Return a QDateTime with the correct time zone instead of the QString,
only works when the qt_timezone isn't set to the DontConvert. */
+1 -1
View File
@@ -66,7 +66,7 @@ namespace Connectors
createConnection(
QString &&driver, std::function<ConnectionName()> &&connection,
QString &&database, QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::DontConvert},
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QVariantHash &&config = {},
std::optional<bool> returnQDateTime = std::nullopt);
+2 -2
View File
@@ -68,13 +68,13 @@ namespace Orm
explicit DatabaseConnection(
std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::DontConvert},
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QVariantHash &&config = {});
/*! Protected constructor for SQLite connection. */
explicit DatabaseConnection(
std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::DontConvert},
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
std::optional<bool> returnQDateTime = true,
QVariantHash &&config = {});
+2 -2
View File
@@ -21,7 +21,7 @@ namespace Orm
explicit MySqlConnection(
std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::DontConvert},
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QVariantHash &&config = {});
public:
@@ -33,7 +33,7 @@ namespace Orm
std::shared_ptr<MySqlConnection>
create(std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::DontConvert},
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QVariantHash &&config = {});
/* Getters / Setters */
+3 -3
View File
@@ -184,13 +184,13 @@ namespace Query
};
/*! Determine how the QDateTime time zone will be converted, it's saved
in the qt_timezone database connection configuration option. */
in the qt_timezone database connection's configuration option. */
struct QtTimeZoneConfig
{
/*! Time zone type saved in the value data member. */
QtTimeZoneType type {QtTimeZoneType::DontConvert};
QtTimeZoneType type {QtTimeZoneType::QtTimeSpec};
/*! Time zone value. */
QVariant value {};
QVariant value {Qt::UTC}; // UTC is the default timezone, not the Qt::LocalTime (it overrides this default)
/*! Equality comparison operator for the QtTimeZoneConfig. */
inline bool operator==(const QtTimeZoneConfig &) const = default;
+2 -2
View File
@@ -23,7 +23,7 @@ namespace Orm
explicit PostgresConnection(
std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::DontConvert},
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QVariantHash &&config = {});
public:
@@ -35,7 +35,7 @@ namespace Orm
std::shared_ptr<PostgresConnection>
create(std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::DontConvert},
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
QVariantHash &&config = {});
/* Getters */
+2 -2
View File
@@ -21,7 +21,7 @@ namespace Orm
explicit SQLiteConnection(
std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::DontConvert},
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
std::optional<bool> returnQDateTime = true,
QVariantHash &&config = {});
@@ -34,7 +34,7 @@ namespace Orm
std::shared_ptr<SQLiteConnection>
create(std::function<Connectors::ConnectionName()> &&connection,
QString &&database = "", QString &&tablePrefix = "",
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::DontConvert},
QtTimeZoneConfig &&qtTimeZone = {QtTimeZoneType::QtTimeSpec, Qt::UTC},
std::optional<bool> returnQDateTime = true,
QVariantHash &&config = {});
+9 -2
View File
@@ -42,7 +42,7 @@ QtTimeZoneConfig
Configuration::prepareQtTimeZone(const QVariantHash &config, const QString &connection)
{
if (!config.contains(qt_timezone))
return {QtTimeZoneType::DontConvert, {}};
return {QtTimeZoneType::QtTimeSpec, Qt::UTC};
return prepareQtTimeZone(config[qt_timezone], connection);
}
@@ -52,13 +52,20 @@ Configuration::prepareQtTimeZone(const QVariant &qtTimeZone, const QString &conn
{
// Nothing to do
if (!qtTimeZone.isValid() || qtTimeZone.isNull())
return {QtTimeZoneType::DontConvert, {}};
return {QtTimeZoneType::QtTimeSpec, Qt::UTC};
const auto typeId = Helpers::qVariantTypeId(qtTimeZone);
if (typeId == QMetaType::fromType<Qt::TimeSpec>().id())
return {QtTimeZoneType::QtTimeSpec, qtTimeZone.value<Qt::TimeSpec>()};
// Allow to define the QtTimeZoneType::DontConvert for the qt_timezone config. option
if (typeId == QMetaType::fromType<QtTimeZoneType>().id())
if (const auto qtTimeZoneValue = qtTimeZone.value<QtTimeZoneType>();
qtTimeZoneValue == QtTimeZoneType::DontConvert
)
return {QtTimeZoneType::DontConvert, {}};
if (typeId == QMetaType::fromType<QTimeZone>().id())
return {QtTimeZoneType::QTimeZone,
QVariant::fromValue(qtTimeZone.value<QTimeZone>())};
+12 -4
View File
@@ -285,7 +285,9 @@ Databases::mysqlConfiguration()
{collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)},
// Very important for tests
{timezone_, TZ00},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -321,7 +323,9 @@ Databases::mariaConfiguration()
UTF8MB4Unicode520ci)},
// Very important for tests
{timezone_, TZ00},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -349,7 +353,9 @@ Databases::sqliteConfiguration()
TINYORM_SQLITE_DATABASE)},
{foreign_key_constraints, true},
{check_database_exists, true},
// Specifies what time zone all QDateTime-s will have
/* 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)},
/* Return a QDateTime with the correct time zone instead of the QString,
only works when the qt_timezone isn't set to the DontConvert. */
@@ -376,7 +382,9 @@ Databases::postgresConfiguration()
{password_, qEnvironmentVariable("DB_PGSQL_PASSWORD", EMPTY)},
{charset_, qEnvironmentVariable("DB_PGSQL_CHARSET", UTF8)},
{timezone_, UTC},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -248,7 +248,7 @@ void tst_DatabaseManager::default_MySQL_ConfigurationValues() const
{options_, QVariantHash()},
{Version, {}},
{qt_timezone, QVariant::fromValue(
QtTimeZoneConfig {QtTimeZoneType::DontConvert, {}}
QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, Qt::UTC}
)},
}));
@@ -308,7 +308,7 @@ void tst_DatabaseManager::default_MariaDB_ConfigurationValues() const
{options_, QVariantHash()},
{Version, {}},
{qt_timezone, QVariant::fromValue(
QtTimeZoneConfig {QtTimeZoneType::DontConvert, {}}
QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, Qt::UTC}
)},
}));
@@ -365,7 +365,7 @@ void tst_DatabaseManager::default_PostgreSQL_ConfigurationValues() const
{options_, QVariantHash()},
{dont_drop, QStringList {spatial_ref_sys}},
{qt_timezone, QVariant::fromValue(
QtTimeZoneConfig {QtTimeZoneType::DontConvert, {}}
QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, Qt::UTC}
)},
}));
@@ -422,7 +422,7 @@ void tst_DatabaseManager::default_SQLite_ConfigurationValues() const
{options_, QVariantHash()},
{return_qdatetime, true},
{qt_timezone, QVariant::fromValue(
QtTimeZoneConfig {QtTimeZoneType::DontConvert, {}}
QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, Qt::UTC}
)},
}));
@@ -499,7 +499,7 @@ void tst_DatabaseManager::ssl_MySQL_ConfigurationValues() const
{prefix_indexes, false},
{Version, {}},
{qt_timezone, QVariant::fromValue(
QtTimeZoneConfig {QtTimeZoneType::DontConvert, {}}
QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, Qt::UTC}
)},
// The ssl_cert is only alias to the "SSL_CERT", looks nicer
{ssl_cert, sslCertValue},
@@ -588,7 +588,7 @@ void tst_DatabaseManager::ssl_MariaDB_ConfigurationValues() const
{prefix_indexes, false},
{Version, {}},
{qt_timezone, QVariant::fromValue(
QtTimeZoneConfig {QtTimeZoneType::DontConvert, {}}
QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, Qt::UTC}
)},
// The ssl_cert is only alias to the "SSL_CERT", looks nicer
{ssl_cert, sslCertValue},
@@ -674,7 +674,7 @@ void tst_DatabaseManager::ssl_PostgreSQL_ConfigurationValues() const
{options_, QVariantHash()},
{dont_drop, QStringList {spatial_ref_sys}},
{qt_timezone, QVariant::fromValue(
QtTimeZoneConfig {QtTimeZoneType::DontConvert, {}}
QtTimeZoneConfig {QtTimeZoneType::QtTimeSpec, Qt::UTC}
)},
{sslmode_, sslmodeValue},
{sslcert, sslcertValue},
+12 -4
View File
@@ -97,7 +97,9 @@ std::shared_ptr<DatabaseManager> setupManager()
{charset_, qEnvironmentVariable("DB_MYSQL_CHARSET", UTF8MB4)},
{collation_, qEnvironmentVariable("DB_MYSQL_COLLATION", UTF8MB40900aici)},
{timezone_, TZ00},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -121,7 +123,9 @@ std::shared_ptr<DatabaseManager> setupManager()
UTF8MB4Unicode520ci)},
// SYSTEM - set the time zone to your local MySQL server time zone
{timezone_, TZ00},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -144,7 +148,9 @@ std::shared_ptr<DatabaseManager> setupManager()
{password_, qEnvironmentVariable("DB_PGSQL_PASSWORD", EMPTY)},
{charset_, qEnvironmentVariable("DB_PGSQL_CHARSET", UTF8)},
{timezone_, UTC},
// Specifies what time zone all QDateTime-s will have
/* 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)},
{prefix_, EMPTY},
{prefix_indexes, false},
@@ -161,7 +167,9 @@ std::shared_ptr<DatabaseManager> setupManager()
{database_, qEnvironmentVariable("DB_SQLITE_DATABASE", {})},
{foreign_key_constraints, true},
{check_database_exists, true},
// Specifies what time zone all QDateTime-s will have
/* 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)},
/* Return a QDateTime with the correct time zone instead of the QString,
only works when the qt_timezone isn't set to the DontConvert. */