diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index b9c6d727c8..9ccb0e5f02 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -607,9 +607,11 @@ QString QTimeZone::abbreviation(const QDateTime &atDateTime) const int QTimeZone::offsetFromUtc(const QDateTime &atDateTime) const { - if (isValid()) - return d->offsetFromUtc(atDateTime.toMSecsSinceEpoch()); - + if (isValid()) { + const int offset = d->offsetFromUtc(atDateTime.toMSecsSinceEpoch()); + if (offset != QTimeZonePrivate::invalidSeconds()) + return offset; + } return 0; } @@ -627,9 +629,11 @@ int QTimeZone::offsetFromUtc(const QDateTime &atDateTime) const int QTimeZone::standardTimeOffset(const QDateTime &atDateTime) const { - if (isValid()) - return d->standardTimeOffset(atDateTime.toMSecsSinceEpoch()); - + if (isValid()) { + const int offset = d->standardTimeOffset(atDateTime.toMSecsSinceEpoch()); + if (offset != QTimeZonePrivate::invalidSeconds()) + return offset; + } return 0; } @@ -647,9 +651,11 @@ int QTimeZone::standardTimeOffset(const QDateTime &atDateTime) const int QTimeZone::daylightTimeOffset(const QDateTime &atDateTime) const { - if (hasDaylightTime()) - return d->daylightTimeOffset(atDateTime.toMSecsSinceEpoch()); - + if (hasDaylightTime()) { + const int offset = d->daylightTimeOffset(atDateTime.toMSecsSinceEpoch()); + if (offset != QTimeZonePrivate::invalidSeconds()) + return offset; + } return 0; } diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index be00f658bc..9053d12f01 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -224,7 +224,10 @@ QString QTimeZonePrivate::abbreviation(qint64 atMSecsSinceEpoch) const int QTimeZonePrivate::offsetFromUtc(qint64 atMSecsSinceEpoch) const { - return standardTimeOffset(atMSecsSinceEpoch) + daylightTimeOffset(atMSecsSinceEpoch); + const int std = standardTimeOffset(atMSecsSinceEpoch); + const int dst = daylightTimeOffset(atMSecsSinceEpoch); + const int bad = invalidSeconds(); + return std == bad || dst == bad ? bad : std + dst; } int QTimeZonePrivate::standardTimeOffset(qint64 atMSecsSinceEpoch) const diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp index 92676108e0..9c505e5baa 100644 --- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp @@ -996,10 +996,10 @@ void tst_QTimeZone::malformed() const QDateTime now = QDateTime::currentDateTime(); QTimeZone barf("QUT4tCZ0 , /"); if (barf.isValid()) - barf.offsetFromUtc(now); + QCOMPARE(barf.offsetFromUtc(now), 0); barf = QTimeZone("QtC+09,,MA"); if (barf.isValid()) - barf.offsetFromUtc(now); + QCOMPARE(barf.offsetFromUtc(now), 0); } void tst_QTimeZone::utcTest()