QDateTime: Ensure a valid timezone when using the "offset constructor".
The timeZone() function used to assert when called on such an object (or, for a release build, return an invalid time zone). Change-Id: I6ae8316b2ad76f1f868e2498f7ce8aa3fcabf4a6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
be2e0f75ae
commit
c619d2daac
@ -3123,6 +3123,7 @@ QTimeZone QDateTime::timeZone() const
|
||||
case Qt::UTC:
|
||||
return QTimeZone::utc();
|
||||
case Qt::OffsetFromUTC:
|
||||
return QTimeZone(d->m_offsetFromUtc);
|
||||
case Qt::TimeZone:
|
||||
Q_ASSERT(d->m_timeZone.isValid());
|
||||
return d->m_timeZone;
|
||||
|
@ -2170,6 +2170,7 @@ void tst_QDateTime::offsetFromUtc()
|
||||
// Offset constructor
|
||||
QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0, 0), Qt::OffsetFromUTC, 60 * 60);
|
||||
QCOMPARE(dt1.offsetFromUtc(), 60 * 60);
|
||||
QVERIFY(dt1.timeZone().isValid());
|
||||
dt1 = QDateTime(QDate(2013, 1, 1), QTime(1, 0, 0), Qt::OffsetFromUTC, -60 * 60);
|
||||
QCOMPARE(dt1.offsetFromUtc(), -60 * 60);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user