SQL/OCI: Correctly calculate utc offset string when icu is not available
When ICU is not available, QTimeZone::displayName() does not return a valid timezone offset string so the OCI driver will get a wrong utc offset string and inserting a QDateTime will go wrong. Fix it by creating the utc offset string by ourself (toOffsetString() inside qdatetime.cpp is static and therefore not accessible for us). Pick-to: 6.5 6.4 6.2 5.15 Fixes: QTBUG-111275 Change-Id: Ib724d760688614e162246e1e028ee5e004cc9477 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
aa111ada08
commit
6b9977c4ad
@ -131,6 +131,15 @@ public:
|
||||
~QOCIDateTime();
|
||||
OCIDateTime *dateTime;
|
||||
static QDateTime fromOCIDateTime(OCIEnv *env, OCIError *err, OCIDateTime *dt);
|
||||
static QString toOffsetString(const QDateTime &dt)
|
||||
{
|
||||
const auto offset = dt.offsetFromUtc();
|
||||
const auto offsetAbs = qAbs(offset) / 60;
|
||||
return QString::asprintf("%c%02d:%02d",
|
||||
offset >= 0 ? '+' : '-',
|
||||
offsetAbs / 60,
|
||||
offsetAbs % 60);
|
||||
}
|
||||
};
|
||||
|
||||
QOCIDateTime::QOCIDateTime(OCIEnv *env, OCIError *err, const QDateTime &dt)
|
||||
@ -140,8 +149,8 @@ QOCIDateTime::QOCIDateTime(OCIEnv *env, OCIError *err, const QDateTime &dt)
|
||||
if (dt.isValid()) {
|
||||
const QDate date = dt.date();
|
||||
const QTime time = dt.time();
|
||||
// Zone in +hh:mm format (stripping UTC prefix from OffsetName)
|
||||
QString timeZone = dt.timeZone().displayName(dt, QTimeZone::OffsetName).mid(3);
|
||||
// Zone in +hh:mm format
|
||||
const QString timeZone = toOffsetString(dt);
|
||||
const OraText *tz = reinterpret_cast<const OraText *>(timeZone.utf16());
|
||||
OCIDateTimeConstruct(env, err, dateTime, date.year(), date.month(), date.day(), time.hour(),
|
||||
time.minute(), time.second(), time.msec() * 1000000,
|
||||
|
Loading…
Reference in New Issue
Block a user