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:
Thiago Macieira 2015-02-21 23:31:02 -08:00
parent 6716fe8cfd
commit 402f994f12
3 changed files with 23 additions and 0 deletions

View File

@ -619,6 +619,15 @@ QTimeZonePrivate *QUtcTimeZonePrivate::clone()
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)
{
m_id = zoneId;

View File

@ -181,6 +181,8 @@ public:
QTimeZonePrivate *clone();
Data data(qint64 forMSecsSinceEpoch) const Q_DECL_OVERRIDE;
QLocale::Country country() const Q_DECL_OVERRIDE;
QString comment() const Q_DECL_OVERRIDE;

View File

@ -2804,10 +2804,12 @@ void tst_QDateTime::timeZones() const
QCOMPARE(invalidDateTime.time(), QTime(0, 0, 0));
QTimeZone nzTz = QTimeZone("Pacific/Auckland");
QTimeZone nzTzOffset = QTimeZone(12 * 3600);
// During Standard Time NZ is +12:00
QDateTime utcStd(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC);
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.timeSpec(), Qt::TimeZone);
@ -2819,6 +2821,16 @@ void tst_QDateTime::timeZones() const
QCOMPARE(nzStd.isDaylightTime(), false);
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
QDateTime utcDst(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC);
QDateTime nzDst(QDate(2012, 1, 1), QTime(13, 0, 0), nzTz);