Timezones: Fix handling of offset-from-UTC QTimeZones
Those QTimeZones failed to convert to other timezones because the data() virtual function was never overridden and reimplemented. That meant all QUtcTimeZonePrivate objects were *really* UTC, with no offset. Task-number: QTBUG-44600 Change-Id: Ia0aac2f09e9245339951ffff13c5294bb783c674 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
6716fe8cfd
commit
402f994f12
@ -619,6 +619,15 @@ QTimeZonePrivate *QUtcTimeZonePrivate::clone()
|
|||||||
return new QUtcTimeZonePrivate(*this);
|
return new QUtcTimeZonePrivate(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTimeZonePrivate::Data QUtcTimeZonePrivate::data(qint64 forMSecsSinceEpoch) const
|
||||||
|
{
|
||||||
|
Data d = invalidData();
|
||||||
|
d.abbreviation = m_abbreviation;
|
||||||
|
d.atMSecsSinceEpoch = forMSecsSinceEpoch;
|
||||||
|
d.offsetFromUtc = m_offsetFromUtc;
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
void QUtcTimeZonePrivate::init(const QByteArray &zoneId)
|
void QUtcTimeZonePrivate::init(const QByteArray &zoneId)
|
||||||
{
|
{
|
||||||
m_id = zoneId;
|
m_id = zoneId;
|
||||||
|
@ -181,6 +181,8 @@ public:
|
|||||||
|
|
||||||
QTimeZonePrivate *clone();
|
QTimeZonePrivate *clone();
|
||||||
|
|
||||||
|
Data data(qint64 forMSecsSinceEpoch) const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
QLocale::Country country() const Q_DECL_OVERRIDE;
|
QLocale::Country country() const Q_DECL_OVERRIDE;
|
||||||
QString comment() const Q_DECL_OVERRIDE;
|
QString comment() const Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
@ -2804,10 +2804,12 @@ void tst_QDateTime::timeZones() const
|
|||||||
QCOMPARE(invalidDateTime.time(), QTime(0, 0, 0));
|
QCOMPARE(invalidDateTime.time(), QTime(0, 0, 0));
|
||||||
|
|
||||||
QTimeZone nzTz = QTimeZone("Pacific/Auckland");
|
QTimeZone nzTz = QTimeZone("Pacific/Auckland");
|
||||||
|
QTimeZone nzTzOffset = QTimeZone(12 * 3600);
|
||||||
|
|
||||||
// During Standard Time NZ is +12:00
|
// During Standard Time NZ is +12:00
|
||||||
QDateTime utcStd(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC);
|
QDateTime utcStd(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC);
|
||||||
QDateTime nzStd(QDate(2012, 6, 1), QTime(12, 0, 0), nzTz);
|
QDateTime nzStd(QDate(2012, 6, 1), QTime(12, 0, 0), nzTz);
|
||||||
|
QDateTime nzStdOffset(QDate(2012, 6, 1), QTime(12, 0, 0), nzTzOffset);
|
||||||
|
|
||||||
QCOMPARE(nzStd.isValid(), true);
|
QCOMPARE(nzStd.isValid(), true);
|
||||||
QCOMPARE(nzStd.timeSpec(), Qt::TimeZone);
|
QCOMPARE(nzStd.timeSpec(), Qt::TimeZone);
|
||||||
@ -2819,6 +2821,16 @@ void tst_QDateTime::timeZones() const
|
|||||||
QCOMPARE(nzStd.isDaylightTime(), false);
|
QCOMPARE(nzStd.isDaylightTime(), false);
|
||||||
QCOMPARE(nzStd.toMSecsSinceEpoch(), utcStd.toMSecsSinceEpoch());
|
QCOMPARE(nzStd.toMSecsSinceEpoch(), utcStd.toMSecsSinceEpoch());
|
||||||
|
|
||||||
|
QCOMPARE(nzStdOffset.isValid(), true);
|
||||||
|
QCOMPARE(nzStdOffset.timeSpec(), Qt::TimeZone);
|
||||||
|
QCOMPARE(nzStdOffset.date(), QDate(2012, 6, 1));
|
||||||
|
QCOMPARE(nzStdOffset.time(), QTime(12, 0, 0));
|
||||||
|
QVERIFY(nzStdOffset.timeZone() == nzTzOffset);
|
||||||
|
QCOMPARE(nzStdOffset.timeZone().id(), QByteArray("UTC+12:00"));
|
||||||
|
QCOMPARE(nzStdOffset.offsetFromUtc(), 43200);
|
||||||
|
QCOMPARE(nzStdOffset.isDaylightTime(), false);
|
||||||
|
QCOMPARE(nzStdOffset.toMSecsSinceEpoch(), utcStd.toMSecsSinceEpoch());
|
||||||
|
|
||||||
// During Daylight Time NZ is +13:00
|
// During Daylight Time NZ is +13:00
|
||||||
QDateTime utcDst(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC);
|
QDateTime utcDst(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC);
|
||||||
QDateTime nzDst(QDate(2012, 1, 1), QTime(13, 0, 0), nzTz);
|
QDateTime nzDst(QDate(2012, 1, 1), QTime(13, 0, 0), nzTz);
|
||||||
|
Loading…
Reference in New Issue
Block a user