diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index b54ae214b02..f2ed537d982 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -226,8 +226,8 @@ bool QDirSortItemComparator::operator()(const QDirSortItem &n1, const QDirSortIt // find timezones, which is incredibly expensive. As we aren't // presenting these to the user, we don't care (at all) about the // local timezone, so force them to UTC to avoid that conversion. - firstModified.setTimeSpec(Qt::UTC); - secondModified.setTimeSpec(Qt::UTC); + firstModified.setTimeZone(QTimeZone::UTC); + secondModified.setTimeZone(QTimeZone::UTC); r = firstModified.msecsTo(secondModified); break; diff --git a/src/corelib/io/qfilesystemengine_win.cpp b/src/corelib/io/qfilesystemengine_win.cpp index f80a6805e90..6d085d98c99 100644 --- a/src/corelib/io/qfilesystemengine_win.cpp +++ b/src/corelib/io/qfilesystemengine_win.cpp @@ -1822,7 +1822,7 @@ static inline QDateTime fileTimeToQDateTime(const FILETIME *time) FileTimeToSystemTime(time, &sTime); return QDateTime(QDate(sTime.wYear, sTime.wMonth, sTime.wDay), QTime(sTime.wHour, sTime.wMinute, sTime.wSecond, sTime.wMilliseconds), - Qt::UTC); + QTimeZone::UTC); } QDateTime QFileSystemMetaData::birthTime() const diff --git a/src/corelib/io/qfilesystemmetadata_p.h b/src/corelib/io/qfilesystemmetadata_p.h index 986ec5ca689..cb19b98c335 100644 --- a/src/corelib/io/qfilesystemmetadata_p.h +++ b/src/corelib/io/qfilesystemmetadata_p.h @@ -18,6 +18,7 @@ #include "qplatformdefs.h" #include #include +#include #include // Platform-specific includes @@ -264,13 +265,29 @@ inline QDateTime QFileSystemMetaData::fileTime(QAbstractFileEngine::FileTime tim #if defined(Q_OS_UNIX) inline QDateTime QFileSystemMetaData::birthTime() const -{ return birthTime_ ? QDateTime::fromMSecsSinceEpoch(birthTime_, Qt::UTC) : QDateTime(); } +{ + return birthTime_ + ? QDateTime::fromMSecsSinceEpoch(birthTime_, QTimeZone::UTC) + : QDateTime(); +} inline QDateTime QFileSystemMetaData::metadataChangeTime() const -{ return metadataChangeTime_ ? QDateTime::fromMSecsSinceEpoch(metadataChangeTime_, Qt::UTC) : QDateTime(); } +{ + return metadataChangeTime_ + ? QDateTime::fromMSecsSinceEpoch(metadataChangeTime_, QTimeZone::UTC) + : QDateTime(); +} inline QDateTime QFileSystemMetaData::modificationTime() const -{ return modificationTime_ ? QDateTime::fromMSecsSinceEpoch(modificationTime_, Qt::UTC) : QDateTime(); } +{ + return modificationTime_ + ? QDateTime::fromMSecsSinceEpoch(modificationTime_, QTimeZone::UTC) + : QDateTime(); +} inline QDateTime QFileSystemMetaData::accessTime() const -{ return accessTime_ ? QDateTime::fromMSecsSinceEpoch(accessTime_, Qt::UTC) : QDateTime(); } +{ + return accessTime_ + ? QDateTime::fromMSecsSinceEpoch(accessTime_, QTimeZone::UTC) + : QDateTime(); +} inline uint QFileSystemMetaData::userId() const { return userId_; } inline uint QFileSystemMetaData::groupId() const { return groupId_; } diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index e9b351166f9..604de7891b0 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -17,6 +17,8 @@ #include #include +#include +#include #include #include #include @@ -798,7 +800,7 @@ static QCborValue::Type convertToExtendedType(QCborContainerPrivate *d) ok = convertDoubleTo(round(e.fpvalue() * 1000), &msecs); } if (ok) - dt = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC); + dt = QDateTime::fromMSecsSinceEpoch(msecs, QTimeZone::UTC); } if (dt.isValid()) { QByteArray text = dt.toString(Qt::ISODateWithMs).toLatin1(); diff --git a/src/corelib/time/qdatetimeparser.cpp b/src/corelib/time/qdatetimeparser.cpp index 8daf926c45a..5eb8376d29c 100644 --- a/src/corelib/time/qdatetimeparser.cpp +++ b/src/corelib/time/qdatetimeparser.cpp @@ -6,14 +6,12 @@ #include "private/qstringiterator_p.h" #include "qdatastream.h" -#include "qset.h" -#include "qvarlengtharray.h" -#include "qlocale.h" #include "qdatetime.h" -#if QT_CONFIG(timezone) -#include "qtimezone.h" -#endif #include "qdebug.h" +#include "qlocale.h" +#include "qset.h" +#include "qtimezone.h" +#include "qvarlengtharray.h" //#define QDATETIMEPARSER_DEBUG #if defined (QDATETIMEPARSER_DEBUG) && !defined(QT_NO_DEBUG_STREAM) @@ -134,9 +132,7 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const int minute = time.minute(); int second = time.second(); int msec = time.msec(); - Qt::TimeSpec tspec = v.timeSpec(); - // Only offset from UTC is amenable to setting an int value: - int offset = tspec == Qt::OffsetFromUTC ? v.offsetFromUtc() : 0; + QTimeZone timeZone = v.timeRepresentation(); const SectionNode &node = sectionNodes.at(index); switch (node.type) { @@ -168,8 +164,8 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const case TimeZoneSection: if (newVal < absoluteMin(index) || newVal > absoluteMax(index)) return false; - tspec = Qt::OffsetFromUTC; - offset = newVal; + // Only offset from UTC is amenable to setting an int value: + timeZone = QTimeZone::fromSecondsAheadOfUtc(newVal); break; case AmPmSection: hour = (newVal == 0 ? hour % 12 : (hour % 12) + 12); break; default: @@ -209,12 +205,7 @@ bool QDateTimeParser::setDigit(QDateTime &v, int index, int newVal) const if (!newDate.isValid() || !newTime.isValid()) return false; - // Preserve zone: - v = -#if QT_CONFIG(timezone) - tspec == Qt::TimeZone ? QDateTime(newDate, newTime, v.timeZone()) : -#endif - QDateTime(newDate, newTime, tspec, offset); + v = QDateTime(newDate, newTime, timeZone); return true; } @@ -231,11 +222,7 @@ int QDateTimeParser::absoluteMax(int s, const QDateTime &cur) const const SectionNode &sn = sectionNode(s); switch (sn.type) { case TimeZoneSection: -#if QT_CONFIG(timezone) return QTimeZone::MaxUtcOffsetSecs; -#else - return +14 * 3600; // NB: copied from QTimeZone -#endif case Hour24Section: case Hour12Section: // This is special-cased in parseSection. @@ -279,11 +266,7 @@ int QDateTimeParser::absoluteMin(int s) const const SectionNode &sn = sectionNode(s); switch (sn.type) { case TimeZoneSection: -#if QT_CONFIG(timezone) return QTimeZone::MinUtcOffsetSecs; -#else - return -14 * 3600; // NB: copied from QTimeZone -#endif case Hour24Section: case Hour12Section: case MinuteSection: @@ -1179,26 +1162,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, bool fixup) const int second = defaultTime.second(); int msec = defaultTime.msec(); int dayofweek = calendar.dayOfWeek(defaultDate); - Qt::TimeSpec tspec = defaultValue.timeSpec(); - int zoneOffset = 0; // In seconds; local - UTC -#if QT_CONFIG(timezone) - QTimeZone timeZone; -#endif - switch (tspec) { - case Qt::OffsetFromUTC: // timeZone is ignored - zoneOffset = defaultValue.offsetFromUtc(); - break; -#if QT_CONFIG(timezone) - case Qt::TimeZone: - timeZone = defaultValue.timeZone(); - if (timeZone.isValid()) - zoneOffset = timeZone.offsetFromUtc(defaultValue); - // else: is there anything we can do about this ? - break; -#endif - default: // zoneOffset and timeZone are ignored - break; - } + QTimeZone timeZone = defaultValue.timeRepresentation(); int ampm = -1; Sections isSet = NoSection; @@ -1215,6 +1179,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, bool fixup) const pos += separator.size(); sectionNodes[index].pos = pos; int *current = nullptr; + int zoneOffset; // Needed to serve as *current when setting zone const SectionNode sn = sectionNodes.at(index); ParsedSection sect; @@ -1222,12 +1187,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, bool fixup) const const QDate date = actualDate(isSet, calendar, year, year2digits, month, day, dayofweek); const QTime time = actualTime(isSet, hour, hour12, ampm, minute, second, msec); - sect = parseSection( -#if QT_CONFIG(timezone) - tspec == Qt::TimeZone ? QDateTime(date, time, timeZone) : -#endif - QDateTime(date, time, tspec, zoneOffset), - index, pos); + sect = parseSection(QDateTime(date, time, timeZone), index, pos); } QDTPDEBUG << "sectionValue" << sn.name() << m_text @@ -1262,15 +1222,18 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, bool fixup) const const bool isUtc = zoneName == "Z"_L1 || zoneName == "UTC"_L1; if (isUtc || isUtcOffset) { - tspec = sect.value ? Qt::OffsetFromUTC : Qt::UTC; + timeZone = QTimeZone::fromSecondsAheadOfUtc(sect.value); } else { #if QT_CONFIG(timezone) - timeZone = QTimeZone(zoneName.toLatin1()); - tspec = timeZone.isValid() - ? Qt::TimeZone - : (Q_ASSERT(startsWithLocalTimeZone(zoneName)), Qt::LocalTime); + QTimeZone namedZone = QTimeZone(zoneName.toLatin1()); + if (namedZone.isValid()) { + timeZone = namedZone; + } else { + Q_ASSERT(startsWithLocalTimeZone(zoneName)); + timeZone = QTimeZone::LocalTime; + } #else - tspec = Qt::LocalTime; + timeZone = QTimeZone::LocalTime; #endif } } @@ -1412,11 +1375,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, bool fixup) const const QDate date(year, month, day, calendar); const QTime time(hour, minute, second, msec); - const QDateTime when = -#if QT_CONFIG(timezone) - tspec == Qt::TimeZone ? QDateTime(date, time, timeZone) : -#endif - QDateTime(date, time, tspec, zoneOffset); + const QDateTime when = QDateTime(date, time, timeZone); // If hour wasn't specified, check the default we're using exists on the // given date (which might be a spring-forward, skipping an hour). @@ -1425,11 +1384,7 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, bool fixup) const case QMetaType::QDateTime: { qint64 msecs = when.toMSecsSinceEpoch(); // Fortunately, that gets a useful answer, even though when is invalid ... - const QDateTime replace = -#if QT_CONFIG(timezone) - tspec == Qt::TimeZone ? QDateTime::fromMSecsSinceEpoch(msecs, timeZone) : -#endif - QDateTime::fromMSecsSinceEpoch(msecs, tspec, zoneOffset); + const QDateTime replace = QDateTime::fromMSecsSinceEpoch(msecs, timeZone); const QTime tick = replace.time(); if (replace.date() == date && (!(isSet & MinuteSection) || tick.minute() == minute) @@ -1440,11 +1395,11 @@ QDateTimeParser::scanString(const QDateTime &defaultValue, bool fixup) const } break; case QMetaType::QDate: // Don't care about time, so just use start of day (and ignore spec): - return StateNode(date.startOfDay(Qt::UTC), state, padding, conflicts); + return StateNode(date.startOfDay(QTimeZone::UTC), state, padding, conflicts); break; case QMetaType::QTime: - // Don't care about date or spec, so pick a safe spec: - return StateNode(QDateTime(date, time, Qt::UTC), state, padding, conflicts); + // Don't care about date or representation, so pick a safe representation: + return StateNode(QDateTime(date, time, QTimeZone::UTC), state, padding, conflicts); default: Q_UNREACHABLE_RETURN(StateNode()); } @@ -2192,7 +2147,7 @@ QString QDateTimeParser::stateName(State s) const // Only called when we want only one of date or time; use UTC to avoid bogus DST issues. bool QDateTimeParser::fromString(const QString &t, QDate *date, QTime *time) const { - QDateTime val(QDate(1900, 1, 1).startOfDay(Qt::UTC)); + QDateTime val(QDate(1900, 1, 1).startOfDay(QTimeZone::UTC)); const StateNode tmp = parse(t, -1, val, false); if (tmp.state != Acceptable || tmp.conflicts) return false; @@ -2232,7 +2187,7 @@ QDateTime QDateTimeParser::getMinimum() const // method. At the time of writing, this is done by QDateTimeEditPrivate. // Cache the only case - static const QDateTime localTimeMin(QDATETIMEEDIT_DATE_MIN.startOfDay(Qt::LocalTime)); + static const QDateTime localTimeMin(QDATETIMEEDIT_DATE_MIN.startOfDay()); return localTimeMin; } @@ -2243,7 +2198,7 @@ QDateTime QDateTimeParser::getMaximum() const // method. At the time of writing, this is done by QDateTimeEditPrivate. // Cache the only case - static const QDateTime localTimeMax(QDATETIMEEDIT_DATE_MAX.endOfDay(Qt::LocalTime)); + static const QDateTime localTimeMax(QDATETIMEEDIT_DATE_MAX.endOfDay()); return localTimeMax; } diff --git a/src/corelib/time/qtimezone.cpp b/src/corelib/time/qtimezone.cpp index ec4ec84b5c1..3bd7489ebb7 100644 --- a/src/corelib/time/qtimezone.cpp +++ b/src/corelib/time/qtimezone.cpp @@ -331,7 +331,7 @@ Q_GLOBAL_STATIC(QTimeZoneSingleton, global_tz); For example, for time zone "Europe/Berlin" the OffsetDate in standard and DST might be: \list - \li atUtc = QDateTime(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::UTC) + \li atUtc = QDateTime(QDate(2013, 1, 1), QTime(0, 0), QTimeZone::UTC) \li offsetFromUtc = 3600 \li standardTimeOffset = 3600 \li daylightTimeOffset = 0 @@ -339,7 +339,7 @@ Q_GLOBAL_STATIC(QTimeZoneSingleton, global_tz); \endlist \list - \li atUtc = QDateTime(QDate(2013, 6, 1), QTime(0, 0, 0), Qt::UTC) + \li atUtc = QDateTime(QDate(2013, 6, 1), QTime(0, 0), QTimeZone::UTC) \li offsetFromUtc = 7200 \li standardTimeOffset = 3600 \li daylightTimeOffset = 3600 @@ -1584,7 +1584,7 @@ QDataStream &operator>>(QDataStream &ds, QTimeZone &tz) // zone, with the right offset, ignoring the other data: tz = QTimeZone(ianaId.toUtf8()); if (!tz.isValid() || tz.hasDaylightTime() - || tz.offsetFromUtc(QDateTime::fromMSecsSinceEpoch(0, Qt::UTC)) != utcOffset) { + || tz.offsetFromUtc(QDateTime::fromMSecsSinceEpoch(0, QTimeZone::UTC)) != utcOffset) { // Construct a custom timezone using the saved values: tz = QTimeZone(ianaId.toUtf8(), utcOffset, name, abbreviation, QLocale::Territory(territory), comment); diff --git a/src/corelib/time/qtimezoneprivate.cpp b/src/corelib/time/qtimezoneprivate.cpp index 53be1330dc0..f55668f3a32 100644 --- a/src/corelib/time/qtimezoneprivate.cpp +++ b/src/corelib/time/qtimezoneprivate.cpp @@ -527,7 +527,7 @@ QTimeZone::OffsetData QTimeZonePrivate::toOffsetData(const QTimeZonePrivate::Dat { QTimeZone::OffsetData offsetData = invalidOffsetData(); if (data.atMSecsSinceEpoch != invalidMSecs()) { - offsetData.atUtc = QDateTime::fromMSecsSinceEpoch(data.atMSecsSinceEpoch, Qt::UTC); + offsetData.atUtc = QDateTime::fromMSecsSinceEpoch(data.atMSecsSinceEpoch, QTimeZone::UTC); offsetData.offsetFromUtc = data.offsetFromUtc; offsetData.standardTimeOffset = data.standardTimeOffset; offsetData.daylightTimeOffset = data.daylightTimeOffset; diff --git a/src/corelib/time/qtimezoneprivate_tz.cpp b/src/corelib/time/qtimezoneprivate_tz.cpp index 9056fe79cc3..960a0944185 100644 --- a/src/corelib/time/qtimezoneprivate_tz.cpp +++ b/src/corelib/time/qtimezoneprivate_tz.cpp @@ -631,20 +631,22 @@ static QList calculatePosixTransitions(const QByteArray Q_ASSERT(startYear <= endYear); for (int year = startYear; year <= endYear; ++year) { - // Note: std and dst, despite being QDateTime(,, Qt::UTC), have the + // Note: std and dst, despite being QDateTime(,, UTC), have the // date() and time() of the *zone*'s description of the transition // moments; the atMSecsSinceEpoch values computed from them are // correctly offse to be UTC-based. QTimeZonePrivate::Data dstData; // Transition to DST - QDateTime dst(calculatePosixDate(dstDateRule, year).startOfDay(Qt::UTC).addSecs(dstTime)); + QDateTime dst(calculatePosixDate(dstDateRule, year) + .startOfDay(QTimeZone::UTC).addSecs(dstTime)); dstData.atMSecsSinceEpoch = dst.toMSecsSinceEpoch() - stdZone.offset * 1000; dstData.offsetFromUtc = dstZone.offset; dstData.standardTimeOffset = stdZone.offset; dstData.daylightTimeOffset = dstZone.offset - stdZone.offset; dstData.abbreviation = dstZone.name; QTimeZonePrivate::Data stdData; // Transition to standard time - QDateTime std(calculatePosixDate(stdDateRule, year).startOfDay(Qt::UTC).addSecs(stdTime)); + QDateTime std(calculatePosixDate(stdDateRule, year) + .startOfDay(QTimeZone::UTC).addSecs(stdTime)); stdData.atMSecsSinceEpoch = std.toMSecsSinceEpoch() - dstZone.offset * 1000; stdData.offsetFromUtc = stdZone.offset; stdData.standardTimeOffset = stdZone.offset; @@ -655,16 +657,16 @@ static QList calculatePosixTransitions(const QByteArray // Handle the special case of fixed state, which may be represented // by fake transitions at start and end of each year: if (dstData.atMSecsSinceEpoch < stdData.atMSecsSinceEpoch) { - if (dst <= QDate(year, 1, 1).startOfDay(Qt::UTC) - && std >= QDate(year, 12, 31).endOfDay(Qt::UTC)) { + if (dst <= QDate(year, 1, 1).startOfDay(QTimeZone::UTC) + && std >= QDate(year, 12, 31).endOfDay(QTimeZone::UTC)) { // Permanent DST: dstData.atMSecsSinceEpoch = lastTranMSecs; result << dstData; return result; } } else { - if (std <= QDate(year, 1, 1).startOfDay(Qt::UTC) - && dst >= QDate(year, 12, 31).endOfDay(Qt::UTC)) { + if (std <= QDate(year, 1, 1).startOfDay(QTimeZone::UTC) + && dst >= QDate(year, 12, 31).endOfDay(QTimeZone::UTC)) { // Permanent Standard time, perversely described: stdData.atMSecsSinceEpoch = lastTranMSecs; result << stdData; @@ -1093,7 +1095,7 @@ QTimeZonePrivate::Data QTzTimeZonePrivate::dataFromRule(QTzTransitionRule rule, QList QTzTimeZonePrivate::getPosixTransitions(qint64 msNear) const { - const int year = QDateTime::fromMSecsSinceEpoch(msNear, Qt::UTC).date().year(); + const int year = QDateTime::fromMSecsSinceEpoch(msNear, QTimeZone::UTC).date().year(); // The Data::atMSecsSinceEpoch of the single entry if zone is constant: qint64 atTime = tranCache().isEmpty() ? msNear : tranCache().last().atMSecsSinceEpoch; return calculatePosixTransitions(cached_data.m_posixRule, year - 1, year + 1, atTime); diff --git a/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp b/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp index 53ba1d13111..fedef67ebe3 100644 --- a/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp +++ b/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include +#include #include class tst_QFileSystemMetaData : public QObject @@ -42,14 +43,14 @@ void tst_QFileSystemMetaData::timeSinceEpoch() data.ftCreationTime = epochToFileTime(afterEpochUtc); meta.fillFromFindData(data); QCOMPARE(meta.birthTime().toUTC(), - QDateTime::fromMSecsSinceEpoch(afterEpochUtc * qint64(1000), Qt::UTC)); + QDateTime::fromMSecsSinceEpoch(afterEpochUtc * qint64(1000), QTimeZone::UTC)); #else QT_STATBUF data; memset(&data, 0, sizeof(data)); data.st_ctime = afterEpochUtc; meta.fillFromStatBuf(data); QCOMPARE(meta.metadataChangeTime().toUTC(), - QDateTime::fromMSecsSinceEpoch(afterEpochUtc * qint64(1000), Qt::UTC)); + QDateTime::fromMSecsSinceEpoch(afterEpochUtc * qint64(1000), QTimeZone::UTC)); #endif } #else // i.e. no Q_AUTOTEST_EXPORT diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 753d3f8b8a4..bf1c165b4f1 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -1328,7 +1328,7 @@ void tst_QSettings::testVariantTypes() testValue("collectList", l4, QVariantList); QDateTime dt = QDateTime::currentDateTime(); - dt.setOffsetFromUtc(3600); + dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(3600)); testValue("dateTime", dt, QDateTime); #if QT_CONFIG(shortcut) diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index d4a12562fb1..fbd17f94b28 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -1280,8 +1281,9 @@ void tst_QVariant::toDateTime_data() << QDateTime( QDate( 2002, 10, 10 ), QTime( 12, 34, 56 ) ); QTest::newRow( "qdate" ) << QVariant( QDate( 2002, 10, 10 ) ) << QDateTime( QDate( 2002, 10, 10 ), QTime( 0, 0, 0 ) ); QTest::newRow( "qstring" ) << QVariant( QString( "2002-10-10T12:34:56" ) ) << QDateTime( QDate( 2002, 10, 10 ), QTime( 12, 34, 56 ) ); - QTest::newRow( "qstring-utc" ) << QVariant( QString( "2002-10-10T12:34:56Z" ) ) - << QDateTime( QDate( 2002, 10, 10 ), QTime( 12, 34, 56 ), Qt::UTC ); + QTest::newRow("qstring-utc") + << QVariant(QString("2002-10-10T12:34:56Z")) + << QDateTime(QDate(2002, 10, 10), QTime(12, 34, 56), QTimeZone::UTC); QTest::newRow( "qstring-with-ms" ) << QVariant( QString( "2002-10-10T12:34:56.789" ) ) << QDateTime( QDate( 2002, 10, 10 ), QTime( 12, 34, 56, 789 ) ); } diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index 0a36aa20842..60ed776f0a6 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -3,10 +3,13 @@ #include #include + #include #include #include +#include #include +#include #include @@ -389,7 +392,7 @@ void tst_QCborValue::extendedTypes_data() QTest::addColumn("correctedTaggedValue"); QCborValue v(QCborValue::Invalid); QDateTime dt = QDateTime::currentDateTimeUtc(); - QDateTime dtTzOffset(dt.date(), dt.time(), Qt::OffsetFromUTC, dt.offsetFromUtc()); + QDateTime dtTzOffset(dt.date(), dt.time(), QTimeZone::fromSecondsAheadOfUtc(dt.offsetFromUtc())); QUuid uuid = QUuid::createUuid(); // non-correcting extended types (tagged value remains unchanged) @@ -413,7 +416,7 @@ void tst_QCborValue::extendedTypes_data() << QCborKnownTags::Uuid << QCborValue(uuid.toRfc4122()) << v; // correcting extended types - QDateTime dtNoMsecs = dt.fromSecsSinceEpoch(dt.toSecsSinceEpoch(), Qt::UTC); + QDateTime dtNoMsecs = dt.fromSecsSinceEpoch(dt.toSecsSinceEpoch(), QTimeZone::UTC); QUrl url("https://example.com/\xc2\xa9 "); QTest::newRow("UnixTime_t:Integer") << QCborValue(dtNoMsecs) << QCborKnownTags::UnixTime_t << QCborValue(dtNoMsecs.toSecsSinceEpoch()) @@ -424,10 +427,11 @@ void tst_QCborValue::extendedTypes_data() QTest::newRow("DateTime::JustDate") << QCborValue(QDateTime({2018, 1, 1}, {})) << QCborKnownTags::DateTimeString << QCborValue("2018-01-01") << QCborValue("2018-01-01T00:00:00.000"); - QTest::newRow("DateTime::TzOffset") << QCborValue(QDateTime({2018, 1, 1}, {9, 0, 0}, Qt::UTC)) - << QCborKnownTags::DateTimeString - << QCborValue("2018-01-01T09:00:00.000+00:00") - << QCborValue("2018-01-01T09:00:00.000Z"); + QTest::newRow("DateTime::TzOffset") + << QCborValue(QDateTime({2018, 1, 1}, {9, 0}, QTimeZone::UTC)) + << QCborKnownTags::DateTimeString + << QCborValue("2018-01-01T09:00:00.000+00:00") + << QCborValue("2018-01-01T09:00:00.000Z"); QTest::newRow("Url:NotNormalized") << QCborValue(url) << QCborKnownTags::Url << QCborValue("HTTPS://EXAMPLE.COM/%c2%a9%20") << QCborValue(url.toString()); @@ -1797,7 +1801,8 @@ void tst_QCborValue::sorting() QCborValue vs2("Hello"), vs3("World"), vs1("foo"); QCborValue va1(QCborValue::Array), va2(QCborArray{1}), va3(QCborArray{0, 0}); QCborValue vm1(QCborValue::Map), vm2(QCborMap{{1, 0}}), vm3(QCborMap{{0, 0}, {1, 0}}); - QCborValue vdt1(QDateTime::fromMSecsSinceEpoch(0, Qt::UTC)), vdt2(QDateTime::currentDateTimeUtc()); + QCborValue vdt1(QDateTime::fromMSecsSinceEpoch(0, QTimeZone::UTC)); + QCborValue vdt2(QDateTime::currentDateTimeUtc()); QCborValue vtagged1(QCborKnownTags::PositiveBignum, QByteArray()), vtagged2(QCborKnownTags::PositiveBignum, 0.0), // bignums are supposed to have byte arrays... vtagged3(QCborKnownTags::Signature, 0), @@ -1954,15 +1959,16 @@ static void addCommonCborData() QTest::newRow("DateTime") << QCborValue(dt) // this is UTC << "\xc0\x78\x18" + dt.toString(Qt::ISODateWithMs).toLatin1() << noxfrm; - QTest::newRow("DateTime-UTC") << QCborValue(QDateTime({2018, 1, 1}, {9, 0, 0}, Qt::UTC)) + QTest::newRow("DateTime-UTC") << QCborValue(QDateTime({2018, 1, 1}, {9, 0}, QTimeZone::UTC)) << raw("\xc0\x78\x18" "2018-01-01T09:00:00.000Z") << noxfrm; - QTest::newRow("DateTime-Local") << QCborValue(QDateTime({2018, 1, 1}, {9, 0, 0}, Qt::LocalTime)) + QTest::newRow("DateTime-Local") << QCborValue(QDateTime({2018, 1, 1}, {9, 0})) << raw("\xc0\x77" "2018-01-01T09:00:00.000") << noxfrm; - QTest::newRow("DateTime+01:00") << QCborValue(QDateTime({2018, 1, 1}, {9, 0, 0}, Qt::OffsetFromUTC, 3600)) - << raw("\xc0\x78\x1d" "2018-01-01T09:00:00.000+01:00") - << noxfrm; + QTest::newRow("DateTime+01:00") + << QCborValue(QDateTime({2018, 1, 1}, {9, 0}, QTimeZone::fromSecondsAheadOfUtc(3600))) + << raw("\xc0\x78\x1d" "2018-01-01T09:00:00.000+01:00") + << noxfrm; QTest::newRow("Url:Empty") << QCborValue(QUrl()) << raw("\xd8\x20\x60") << noxfrm; QTest::newRow("Url") << QCborValue(QUrl("HTTPS://example.com/{%30%31}?q=%3Ca+b%20%C2%A9%3E&%26")) << raw("\xd8\x20\x78\x27" "https://example.com/{01}?q=&%26") @@ -2070,21 +2076,29 @@ void tst_QCborValue::fromCbor_data() QTest::newRow("String:Chunked:Empty") << QCborValue(QString()) << raw("\x7f\xff"); - QTest::newRow("DateTime:NoMilli") << QCborValue(QDateTime::fromSecsSinceEpoch(1515565477, Qt::UTC)) - << raw("\xc0\x74" "2018-01-10T06:24:37Z"); + QTest::newRow("DateTime:NoMilli") + << QCborValue(QDateTime::fromSecsSinceEpoch(1515565477, QTimeZone::UTC)) + << raw("\xc0\x74" "2018-01-10T06:24:37Z"); // date-only is only permitted local time - QTest::newRow("DateTime:NoTime:Local") << QCborValue(QDateTime(QDate(2020, 4, 15), QTime(0, 0), Qt::LocalTime)) - << raw("\xc0\x6a" "2020-04-15"); - QTest::newRow("DateTime:24:00:00") << QCborValue(QDateTime(QDate(2020, 4, 16), QTime(0, 0), Qt::UTC)) - << raw("\xc0\x74" "2020-04-15T24:00:00Z"); - QTest::newRow("DateTime:+00:00") << QCborValue(QDateTime::fromMSecsSinceEpoch(1515565477125, Qt::UTC)) - << raw("\xc0\x78\x1d" "2018-01-10T06:24:37.125+00:00"); - QTest::newRow("DateTime:+01:00") << QCborValue(QDateTime::fromMSecsSinceEpoch(1515565477125, Qt::OffsetFromUTC, 60*60)) - << raw("\xc0\x78\x1d" "2018-01-10T07:24:37.125+01:00"); - QTest::newRow("UnixTime_t:Integer") << QCborValue(QDateTime::fromSecsSinceEpoch(1515565477, Qt::UTC)) - << raw("\xc1\x1a\x5a\x55\xb1\xa5"); - QTest::newRow("UnixTime_t:Double") << QCborValue(QDateTime::fromMSecsSinceEpoch(1515565477125, Qt::UTC)) - << raw("\xc1\xfb\x41\xd6\x95\x6c""\x69\x48\x00\x00"); + QTest::newRow("DateTime:NoTime:Local") + << QCborValue(QDateTime(QDate(2020, 4, 15), QTime(0, 0))) + << raw("\xc0\x6a" "2020-04-15"); + QTest::newRow("DateTime:24:00:00") + << QCborValue(QDateTime(QDate(2020, 4, 16), QTime(0, 0), QTimeZone::UTC)) + << raw("\xc0\x74" "2020-04-15T24:00:00Z"); + QTest::newRow("DateTime:+00:00") + << QCborValue(QDateTime::fromMSecsSinceEpoch(1515565477125, QTimeZone::UTC)) + << raw("\xc0\x78\x1d" "2018-01-10T06:24:37.125+00:00"); + QTest::newRow("DateTime:+01:00") + << QCborValue(QDateTime::fromMSecsSinceEpoch(1515565477125, + QTimeZone::fromSecondsAheadOfUtc(60 * 60))) + << raw("\xc0\x78\x1d" "2018-01-10T07:24:37.125+01:00"); + QTest::newRow("UnixTime_t:Integer") + << QCborValue(QDateTime::fromSecsSinceEpoch(1515565477, QTimeZone::UTC)) + << raw("\xc1\x1a\x5a\x55\xb1\xa5"); + QTest::newRow("UnixTime_t:Double") + << QCborValue(QDateTime::fromMSecsSinceEpoch(1515565477125, QTimeZone::UTC)) + << raw("\xc1\xfb\x41\xd6\x95\x6c""\x69\x48\x00\x00"); QTest::newRow("Url:NotNormalized") << QCborValue(QUrl("https://example.com/\xc2\xa9 ")) << raw("\xd8\x20\x78\x1dHTTPS://EXAMPLE.COM/%c2%a9%20"); @@ -2291,7 +2305,7 @@ void tst_QCborValue::extendedTypeValidation_data() // representation, which means it can't represent dates before year 1 or // after year 9999. { - QDateTime dt(QDate(-1, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime dt(QDate(-1, 1, 1), QTime(0, 0), QTimeZone::UTC); QTest::newRow("UnixTime_t:negative-year") << encode(0xc1, 0x3b, quint64(-dt.toSecsSinceEpoch()) - 1) << QCborValue(QCborKnownTags::UnixTime_t, dt.toSecsSinceEpoch()); @@ -2932,7 +2946,7 @@ void tst_QCborValue::debugOutput_data() QTest::addColumn("v"); QTest::addColumn("expected"); - QDateTime dt(QDate(2020, 4, 18), QTime(13, 41, 22, 123), Qt::UTC); + QDateTime dt(QDate(2020, 4, 18), QTime(13, 41, 22, 123), QTimeZone::UTC); QBitArray bits = QBitArray::fromBits("\x79\x03", 11); QTest::newRow("Undefined") << QCborValue() << "QCborValue()"; diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp index 11da627bd0b..ed5cbbe2104 100644 --- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp @@ -13,9 +13,7 @@ # include #endif #include -#if QT_CONFIG(timezone) #include -#endif #include #include @@ -1935,26 +1933,26 @@ void tst_QLocale::formatTimeZone() { QLocale enUS("en_US"); - QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0, 0), Qt::OffsetFromUTC, 60 * 60); + QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0), QTimeZone::fromSecondsAheadOfUtc(60 * 60)); QCOMPARE(enUS.toString(dt1, "t"), QLatin1String("UTC+01:00")); - QDateTime dt2(QDate(2013, 1, 1), QTime(1, 0, 0), Qt::OffsetFromUTC, -60 * 60); + QDateTime dt2(QDate(2013, 1, 1), QTime(1, 0), QTimeZone::fromSecondsAheadOfUtc(-60 * 60)); QCOMPARE(enUS.toString(dt2, "t"), QLatin1String("UTC-01:00")); - QDateTime dt3(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::UTC); + QDateTime dt3(QDate(2013, 1, 1), QTime(0, 0), QTimeZone::UTC); QCOMPARE(enUS.toString(dt3, "t"), QLatin1String("UTC")); // LocalTime should vary if (europeanTimeZone) { // Time definitely in Standard Time - QDateTime dt4(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::LocalTime); + QDateTime dt4 = QDate(2013, 1, 1).startOfDay(); #ifdef Q_OS_WIN QEXPECT_FAIL("", "Windows only returns long name (QTBUG-32759)", Continue); #endif // Q_OS_WIN QCOMPARE(enUS.toString(dt4, "t"), QLatin1String("CET")); // Time definitely in Daylight Time - QDateTime dt5(QDate(2013, 6, 1), QTime(0, 0, 0), Qt::LocalTime); + QDateTime dt5 = QDate(2013, 6, 1).startOfDay(); #ifdef Q_OS_WIN QEXPECT_FAIL("", "Windows only returns long name (QTBUG-32759)", Continue); #endif // Q_OS_WIN @@ -2051,7 +2049,7 @@ void tst_QLocale::toDateTime_data() << u"ddd, d MMM yyyy HH:mm:ss t"_s << u"Sun, 29 Mar 2020 02:26:3 Z"_s << false; QTest::newRow("s-Z") // Same, but with a format that accepts the single digit: - << "C" << QDateTime(QDate(2020, 3, 29), QTime(2, 26, 3), Qt::UTC) + << "C" << QDateTime(QDate(2020, 3, 29), QTime(2, 26, 3), QTimeZone::UTC) << u"ddd, d MMM yyyy HH:mm:s t"_s << u"Sun, 29 Mar 2020 02:26:3 Z"_s << false; QTest::newRow("RFC-1123") diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 50870244b55..eb92337efb2 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -2,14 +2,14 @@ // Copyright (C) 2016 Intel Corporation. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include // for the icu feature test +#include #include -#if QT_CONFIG(timezone) -#include -#endif -#include -#include + +#include #include +#include + +#include // for the icu feature test class tst_QDate : public QObject { @@ -527,7 +527,7 @@ void tst_QDate::startOfDay_endOfDay() QFETCH(QByteArray, zoneName); QFETCH(QTime, start); QFETCH(QTime, end); - const QTimeZone zone(zoneName); + const auto zone = QTimeZone(zoneName); QVERIFY(zone.isValid()); const bool isSystem = QTimeZone::systemTimeZone() == zone; QDateTime front(date.startOfDay(zone)), back(date.endOfDay(zone)); @@ -546,13 +546,13 @@ void tst_QDate::startOfDay_endOfDay() } if (front.timeSpec() == Qt::LocalTime) break; - front = date.startOfDay(Qt::LocalTime); - back = date.endOfDay(Qt::LocalTime); + front = date.startOfDay(); + back = date.endOfDay(); } while (isSystem); if (end.isValid()) - QCOMPARE(date.addDays(1).startOfDay(Qt::LocalTime).addMSecs(-1), back); + QCOMPARE(date.addDays(1).startOfDay().addMSecs(-1), back); if (start.isValid()) - QCOMPARE(date.addDays(-1).endOfDay(Qt::LocalTime).addMSecs(1), front); + QCOMPARE(date.addDays(-1).endOfDay().addMSecs(1), front); if (!isSystem) { // These might fail if system zone coincides with zone; but only if it // did something similarly unusual on the date picked for this test. @@ -572,12 +572,13 @@ void tst_QDate::startOfDay_endOfDay_fixed_data() { const qint64 kilo(1000); using Bounds = std::numeric_limits; + const auto UTC = QTimeZone::UTC; const QDateTime - first(QDateTime::fromMSecsSinceEpoch(Bounds::min() + 1, Qt::UTC)), - start32sign(QDateTime::fromMSecsSinceEpoch(Q_INT64_C(-0x80000000) * kilo, Qt::UTC)), - end32sign(QDateTime::fromMSecsSinceEpoch(Q_INT64_C(0x80000000) * kilo, Qt::UTC)), - end32unsign(QDateTime::fromMSecsSinceEpoch(Q_INT64_C(0x100000000) * kilo, Qt::UTC)), - last(QDateTime::fromMSecsSinceEpoch(Bounds::max(), Qt::UTC)); + first(QDateTime::fromMSecsSinceEpoch(Bounds::min() + 1, UTC)), + start32sign(QDateTime::fromMSecsSinceEpoch(Q_INT64_C(-0x80000000) * kilo, UTC)), + end32sign(QDateTime::fromMSecsSinceEpoch(Q_INT64_C(0x80000000) * kilo, UTC)), + end32unsign(QDateTime::fromMSecsSinceEpoch(Q_INT64_C(0x100000000) * kilo, UTC)), + last(QDateTime::fromMSecsSinceEpoch(Bounds::max(), UTC)); const struct { const char *name; @@ -605,28 +606,29 @@ void tst_QDate::startOfDay_endOfDay_fixed() const QTime early(0, 0), late(23, 59, 59, 999); QFETCH(QDate, date); - QDateTime start(date.startOfDay(Qt::UTC)); - QDateTime end(date.endOfDay(Qt::UTC)); + QDateTime start(date.startOfDay(QTimeZone::UTC)); + QDateTime end(date.endOfDay(QTimeZone::UTC)); QCOMPARE(start.date(), date); QCOMPARE(end.date(), date); QCOMPARE(start.time(), early); QCOMPARE(end.time(), late); - QCOMPARE(date.addDays(1).startOfDay(Qt::UTC).addMSecs(-1), end); - QCOMPARE(date.addDays(-1).endOfDay(Qt::UTC).addMSecs(1), start); + QCOMPARE(date.addDays(1).startOfDay(QTimeZone::UTC).addMSecs(-1), end); + QCOMPARE(date.addDays(-1).endOfDay(QTimeZone::UTC).addMSecs(1), start); for (int offset = -60 * 16; offset <= 60 * 16; offset += 65) { - start = date.startOfDay(Qt::OffsetFromUTC, offset); - end = date.endOfDay(Qt::OffsetFromUTC, offset); + const auto zone = QTimeZone::fromSecondsAheadOfUtc(offset); + start = date.startOfDay(zone); + end = date.endOfDay(zone); QCOMPARE(start.date(), date); QCOMPARE(end.date(), date); QCOMPARE(start.time(), early); QCOMPARE(end.time(), late); - QCOMPARE(date.addDays(1).startOfDay(Qt::OffsetFromUTC, offset).addMSecs(-1), end); - QCOMPARE(date.addDays(-1).endOfDay(Qt::OffsetFromUTC, offset).addMSecs(1), start); + QCOMPARE(date.addDays(1).startOfDay(zone).addMSecs(-1), end); + QCOMPARE(date.addDays(-1).endOfDay(zone).addMSecs(1), start); } // Minimal testing for LocalTime and TimeZone - QCOMPARE(date.startOfDay(Qt::LocalTime).date(), date); - QCOMPARE(date.endOfDay(Qt::LocalTime).date(), date); + QCOMPARE(date.startOfDay().date(), date); + QCOMPARE(date.endOfDay().date(), date); #if QT_CONFIG(timezone) const QTimeZone cet("Europe/Oslo"); if (cet.isValid()) { @@ -640,10 +642,11 @@ void tst_QDate::startOfDay_endOfDay_bounds() { // Check the days in which QDateTime's range starts and ends: using Bounds = std::numeric_limits; + const auto UTC = QTimeZone::UTC; const QDateTime - first(QDateTime::fromMSecsSinceEpoch(Bounds::min(), Qt::UTC)), - last(QDateTime::fromMSecsSinceEpoch(Bounds::max(), Qt::UTC)), - epoch(QDateTime::fromMSecsSinceEpoch(0, Qt::UTC)); + first(QDateTime::fromMSecsSinceEpoch(Bounds::min(), UTC)), + last(QDateTime::fromMSecsSinceEpoch(Bounds::max(), UTC)), + epoch(QDateTime::fromMSecsSinceEpoch(0, UTC)); // First, check these *are* the start and end of QDateTime's range: QVERIFY(first.isValid()); QVERIFY(last.isValid()); @@ -654,15 +657,15 @@ void tst_QDate::startOfDay_endOfDay_bounds() QVERIFY(!last.addMSecs(1).isValid() || last.addMSecs(1) < last); // Now test start/end methods with them: - QCOMPARE(first.date().endOfDay(Qt::UTC).time(), QTime(23, 59, 59, 999)); - QCOMPARE(last.date().startOfDay(Qt::UTC).time(), QTime(0, 0)); - QVERIFY(!first.date().startOfDay(Qt::UTC).isValid()); - QVERIFY(!last.date().endOfDay(Qt::UTC).isValid()); + QCOMPARE(first.date().endOfDay(UTC).time(), QTime(23, 59, 59, 999)); + QCOMPARE(last.date().startOfDay(UTC).time(), QTime(0, 0)); + QVERIFY(!first.date().startOfDay(UTC).isValid()); + QVERIFY(!last.date().endOfDay(UTC).isValid()); // Test for QTBUG-100873, shouldn't assert: const QDate qdteMin(1752, 9, 14); // Used by QDateTimeEdit - QCOMPARE(qdteMin.startOfDay(Qt::UTC).date(), qdteMin); - QCOMPARE(qdteMin.startOfDay(Qt::LocalTime).date(), qdteMin); + QCOMPARE(qdteMin.startOfDay(UTC).date(), qdteMin); + QCOMPARE(qdteMin.startOfDay().date(), qdteMin); #if QT_CONFIG(timezone) QCOMPARE(qdteMin.startOfDay(QTimeZone::systemTimeZone()).date(), qdteMin); QTimeZone berlin("Europe/Berlin"); diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index d3a02de8eb8..f4a110d2981 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2,11 +2,13 @@ // Copyright (C) 2016 Intel Corporation. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +#include #include -#include -#include + +#include #include +#include #ifdef Q_OS_WIN # include #endif @@ -142,6 +144,7 @@ private Q_SLOTS: private: enum { LocalTimeIsUtc = 0, LocalTimeAheadOfUtc = 1, LocalTimeBehindUtc = -1} localTimeType; + static constexpr auto UTC = QTimeZone::UTC; int preZoneFix; bool zoneIsCET; @@ -271,9 +274,9 @@ void tst_QDateTime::ctor() { QDateTime dt1(QDate(2004, 1, 2), QTime(1, 2, 3)); QCOMPARE(dt1.timeSpec(), Qt::LocalTime); - QDateTime dt2(QDate(2004, 1, 2), QTime(1, 2, 3), Qt::LocalTime); + QDateTime dt2(QDate(2004, 1, 2), QTime(1, 2, 3)); QCOMPARE(dt2.timeSpec(), Qt::LocalTime); - QDateTime dt3(QDate(2004, 1, 2), QTime(1, 2, 3), Qt::UTC); + QDateTime dt3(QDate(2004, 1, 2), QTime(1, 2, 3), UTC); QCOMPARE(dt3.timeSpec(), Qt::UTC); QVERIFY(dt1 == dt2); @@ -287,25 +290,26 @@ void tst_QDateTime::ctor() QDate offsetDate(2013, 1, 1); QTime offsetTime(1, 2, 3); - QDateTime offset1(offsetDate, offsetTime, Qt::OffsetFromUTC); + QDateTime offset1(offsetDate, offsetTime, QTimeZone::fromSecondsAheadOfUtc(0)); QCOMPARE(offset1.timeSpec(), Qt::UTC); QCOMPARE(offset1.offsetFromUtc(), 0); QCOMPARE(offset1.date(), offsetDate); QCOMPARE(offset1.time(), offsetTime); - QDateTime offset2(offsetDate, offsetTime, Qt::OffsetFromUTC, 0); + QDateTime offset2(offsetDate, offsetTime, + QTimeZone::fromDurationAheadOfUtc(std::chrono::seconds{})); QCOMPARE(offset2.timeSpec(), Qt::UTC); QCOMPARE(offset2.offsetFromUtc(), 0); QCOMPARE(offset2.date(), offsetDate); QCOMPARE(offset2.time(), offsetTime); - QDateTime offset3(offsetDate, offsetTime, Qt::OffsetFromUTC, 60 * 60); + QDateTime offset3(offsetDate, offsetTime, QTimeZone::fromSecondsAheadOfUtc(60 * 60)); QCOMPARE(offset3.timeSpec(), Qt::OffsetFromUTC); QCOMPARE(offset3.offsetFromUtc(), 60 * 60); QCOMPARE(offset3.date(), offsetDate); QCOMPARE(offset3.time(), offsetTime); - QDateTime offset4(offsetDate, QTime(0, 0), Qt::OffsetFromUTC, 60 * 60); + QDateTime offset4(offsetDate, QTime(0, 0), QTimeZone::fromSecondsAheadOfUtc(60 * 60)); QCOMPARE(offset4.timeSpec(), Qt::OffsetFromUTC); QCOMPARE(offset4.offsetFromUtc(), 60 * 60); QCOMPARE(offset4.date(), offsetDate); @@ -315,16 +319,16 @@ void tst_QDateTime::ctor() void tst_QDateTime::operator_eq() { QVERIFY(QDateTime() != QDateTime(QDate(1970, 1, 1), QTime(0, 0))); // QTBUG-79006 - QDateTime dt1(QDate(2004, 3, 24), QTime(23, 45, 57), Qt::UTC); - QDateTime dt2(QDate(2005, 3, 11), QTime(0, 0), Qt::UTC); + QDateTime dt1(QDate(2004, 3, 24), QTime(23, 45, 57), UTC); + QDateTime dt2(QDate(2005, 3, 11), QTime(0, 0), UTC); dt2 = dt1; QVERIFY(dt1 == dt2); } void tst_QDateTime::moveSemantics() { - QDateTime dt1{QDate{2004, 3, 24}, QTime{23, 45, 57}, Qt::UTC}; - QDateTime dt2{QDate{2005, 3, 11}, QTime{0, 0}, Qt::UTC}; + QDateTime dt1{QDate{2004, 3, 24}, QTime{23, 45, 57}, UTC}; + QDateTime dt2{QDate{2005, 3, 11}, QTime{0, 0}, UTC}; QDateTime copy = dt1; QDateTime moved = std::move(dt1); QCOMPARE(copy, moved); @@ -341,7 +345,7 @@ void tst_QDateTime::isNull() QVERIFY(dt1.isNull()); dt1.setTime(QTime()); QVERIFY(dt1.isNull()); - dt1.setTimeSpec(Qt::UTC); + dt1.setTimeZone(UTC); QVERIFY(dt1.isNull()); dt1.setTime(QTime(12, 34, 56)); @@ -372,7 +376,7 @@ void tst_QDateTime::isValid() QVERIFY(!dt1.isValid()); dt1.setTime(QTime()); QVERIFY(!dt1.isValid()); - dt1.setTimeSpec(Qt::UTC); + dt1.setTimeZone(UTC); QVERIFY(!dt1.isValid()); dt1.setDate(QDate(2004, 1, 2)); @@ -396,31 +400,31 @@ void tst_QDateTime::isValid() void tst_QDateTime::date() { - QDateTime dt1(QDate(2004, 3, 24), QTime(23, 45, 57), Qt::LocalTime); + QDateTime dt1(QDate(2004, 3, 24), QTime(23, 45, 57)); QCOMPARE(dt1.date(), QDate(2004, 3, 24)); - QDateTime dt2(QDate(2004, 3, 25), QTime(0, 45, 57), Qt::LocalTime); + QDateTime dt2(QDate(2004, 3, 25), QTime(0, 45, 57)); QCOMPARE(dt2.date(), QDate(2004, 3, 25)); - QDateTime dt3(QDate(2004, 3, 24), QTime(23, 45, 57), Qt::UTC); + QDateTime dt3(QDate(2004, 3, 24), QTime(23, 45, 57), UTC); QCOMPARE(dt3.date(), QDate(2004, 3, 24)); - QDateTime dt4(QDate(2004, 3, 25), QTime(0, 45, 57), Qt::UTC); + QDateTime dt4(QDate(2004, 3, 25), QTime(0, 45, 57), UTC); QCOMPARE(dt4.date(), QDate(2004, 3, 25)); } void tst_QDateTime::time() { - QDateTime dt1(QDate(2004, 3, 24), QTime(23, 45, 57), Qt::LocalTime); + QDateTime dt1(QDate(2004, 3, 24), QTime(23, 45, 57)); QCOMPARE(dt1.time(), QTime(23, 45, 57)); - QDateTime dt2(QDate(2004, 3, 25), QTime(0, 45, 57), Qt::LocalTime); + QDateTime dt2(QDate(2004, 3, 25), QTime(0, 45, 57)); QCOMPARE(dt2.time(), QTime(0, 45, 57)); - QDateTime dt3(QDate(2004, 3, 24), QTime(23, 45, 57), Qt::UTC); + QDateTime dt3(QDate(2004, 3, 24), QTime(23, 45, 57), UTC); QCOMPARE(dt3.time(), QTime(23, 45, 57)); - QDateTime dt4(QDate(2004, 3, 25), QTime(0, 45, 57), Qt::UTC); + QDateTime dt4(QDate(2004, 3, 25), QTime(0, 45, 57), UTC); QCOMPARE(dt4.time(), QTime(0, 45, 57)); } @@ -437,10 +441,10 @@ void tst_QDateTime::timeSpec() QCOMPARE(dt1.toTimeSpec(Qt::LocalTime).timeSpec(), Qt::LocalTime); QCOMPARE(dt1.toTimeSpec(Qt::UTC).timeSpec(), Qt::UTC); - QDateTime dt2(QDate(2004, 1, 24), QTime(23, 45, 57), Qt::LocalTime); + QDateTime dt2(QDate(2004, 1, 24), QTime(23, 45, 57)); QCOMPARE(dt2.timeSpec(), Qt::LocalTime); - QDateTime dt3(QDate(2004, 1, 25), QTime(0, 45, 57), Qt::UTC); + QDateTime dt3(QDate(2004, 1, 25), QTime(0, 45, 57), UTC); QCOMPARE(dt3.timeSpec(), Qt::UTC); QDateTime dt4 = QDateTime::currentDateTime(); @@ -449,7 +453,7 @@ void tst_QDateTime::timeSpec() void tst_QDateTime::setDate() { - QDateTime dt1(QDate(2004, 3, 25), QTime(0, 45, 57), Qt::UTC); + QDateTime dt1(QDate(2004, 3, 25), QTime(0, 45, 57), UTC); dt1.setDate(QDate(2004, 6, 25)); QCOMPARE(dt1.date(), QDate(2004, 6, 25)); QCOMPARE(dt1.time(), QTime(0, 45, 57)); @@ -461,7 +465,7 @@ void tst_QDateTime::setDate() QCOMPARE(dt2.time(), QTime(0, 45, 57)); QCOMPARE(dt2.timeSpec(), Qt::LocalTime); - QDateTime dt3(QDate(4004, 3, 25), QTime(0, 45, 57), Qt::UTC); + QDateTime dt3(QDate(4004, 3, 25), QTime(0, 45, 57), UTC); dt3.setDate(QDate(4004, 6, 25)); QCOMPARE(dt3.date(), QDate(4004, 6, 25)); QCOMPARE(dt3.time(), QTime(0, 45, 57)); @@ -473,7 +477,7 @@ void tst_QDateTime::setDate() QCOMPARE(dt4.time(), QTime(0, 45, 57)); QCOMPARE(dt4.timeSpec(), Qt::LocalTime); - QDateTime dt5(QDate(1760, 3, 25), QTime(0, 45, 57), Qt::UTC); + QDateTime dt5(QDate(1760, 3, 25), QTime(0, 45, 57), UTC); dt5.setDate(QDate(1760, 6, 25)); QCOMPARE(dt5.date(), QDate(1760, 6, 25)); QCOMPARE(dt5.time(), QTime(0, 45, 57)); @@ -492,15 +496,15 @@ void tst_QDateTime::setTime_data() QTest::addColumn("newTime"); QTest::newRow("data0") - << QDateTime(QDate(2004, 3, 25), QTime(0, 45, 57), Qt::UTC) << QTime(23, 11, 22); + << QDateTime(QDate(2004, 3, 25), QTime(0, 45, 57), UTC) << QTime(23, 11, 22); QTest::newRow("data1") << QDateTime(QDate(2004, 3, 25), QTime(0, 45, 57)) << QTime(23, 11, 22); QTest::newRow("data2") - << QDateTime(QDate(4004, 3, 25), QTime(0, 45, 57), Qt::UTC) << QTime(23, 11, 22); + << QDateTime(QDate(4004, 3, 25), QTime(0, 45, 57), UTC) << QTime(23, 11, 22); QTest::newRow("data3") << QDateTime(QDate(4004, 3, 25), QTime(0, 45, 57)) << QTime(23, 11, 22); QTest::newRow("data4") - << QDateTime(QDate(1760, 3, 25), QTime(0, 45, 57), Qt::UTC) << QTime(23, 11, 22); + << QDateTime(QDate(1760, 3, 25), QTime(0, 45, 57), UTC) << QTime(23, 11, 22); QTest::newRow("data5") << QDateTime(QDate(1760, 3, 25), QTime(0, 45, 57)) << QTime(23, 11, 22); @@ -533,7 +537,7 @@ void tst_QDateTime::setTimeZone_data() QTimeZone zone; } data[] = { { nullptr, QTimeZone() }, // For time-zone, when supported. - { "UTC", QTimeZone::UTC }, + { "UTC", UTC }, { "LocalTime", QTimeZone() }, { "Offset", QTimeZone::fromSecondsAheadOfUtc(3600) } }; @@ -579,11 +583,11 @@ void tst_QDateTime::setTimeSpec_data() QTest::addColumn("newTimeSpec"); QTest::newRow("UTC => UTC") - << QDateTime(QDate(2004, 3, 25), QTime(0, 45, 57), Qt::UTC) << Qt::UTC; + << QDateTime(QDate(2004, 3, 25), QTime(0, 45, 57), UTC) << Qt::UTC; QTest::newRow("UTC => LocalTime") - << QDateTime(QDate(2004, 3, 25), QTime(0, 45, 57), Qt::UTC) << Qt::LocalTime; + << QDateTime(QDate(2004, 3, 25), QTime(0, 45, 57), UTC) << Qt::LocalTime; QTest::newRow("UTC => OffsetFromUTC") - << QDateTime(QDate(2004, 3, 25), QTime(0, 45, 57), Qt::UTC) << Qt::OffsetFromUTC; + << QDateTime(QDate(2004, 3, 25), QTime(0, 45, 57), UTC) << Qt::OffsetFromUTC; } void tst_QDateTime::setTimeSpec() @@ -608,16 +612,16 @@ void tst_QDateTime::setSecsSinceEpoch() { QDateTime dt1; dt1.setSecsSinceEpoch(0); - QCOMPARE(dt1.toUTC(), QDate(1970, 1, 1).startOfDay(Qt::UTC)); + QCOMPARE(dt1.toUTC(), QDate(1970, 1, 1).startOfDay(UTC)); QCOMPARE(dt1.timeSpec(), Qt::LocalTime); - dt1.setTimeSpec(Qt::UTC); + dt1.setTimeZone(UTC); dt1.setSecsSinceEpoch(0); - QCOMPARE(dt1, QDate(1970, 1, 1).startOfDay(Qt::UTC)); + QCOMPARE(dt1, QDate(1970, 1, 1).startOfDay(UTC)); QCOMPARE(dt1.timeSpec(), Qt::UTC); dt1.setSecsSinceEpoch(123456); - QCOMPARE(dt1, QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36), Qt::UTC)); + QCOMPARE(dt1, QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36), UTC)); if (zoneIsCET) { QDateTime dt2; dt2.setSecsSinceEpoch(123456); @@ -625,7 +629,7 @@ void tst_QDateTime::setSecsSinceEpoch() } dt1.setSecsSinceEpoch((uint)(quint32)-123456); - QCOMPARE(dt1, QDateTime(QDate(2106, 2, 5), QTime(20, 10, 40), Qt::UTC)); + QCOMPARE(dt1, QDateTime(QDate(2106, 2, 5), QTime(20, 10, 40), UTC)); if (zoneIsCET) { QDateTime dt2; dt2.setSecsSinceEpoch((uint)(quint32)-123456); @@ -633,7 +637,7 @@ void tst_QDateTime::setSecsSinceEpoch() } dt1.setSecsSinceEpoch(1214567890); - QCOMPARE(dt1, QDateTime(QDate(2008, 6, 27), QTime(11, 58, 10), Qt::UTC)); + QCOMPARE(dt1, QDateTime(QDate(2008, 6, 27), QTime(11, 58, 10), UTC)); if (zoneIsCET) { QDateTime dt2; dt2.setSecsSinceEpoch(1214567890); @@ -641,21 +645,21 @@ void tst_QDateTime::setSecsSinceEpoch() } dt1.setSecsSinceEpoch(0x7FFFFFFF); - QCOMPARE(dt1, QDateTime(QDate(2038, 1, 19), QTime(3, 14, 7), Qt::UTC)); + QCOMPARE(dt1, QDateTime(QDate(2038, 1, 19), QTime(3, 14, 7), UTC)); if (zoneIsCET) { QDateTime dt2; dt2.setSecsSinceEpoch(0x7FFFFFFF); QCOMPARE(dt2, QDateTime(QDate(2038, 1, 19), QTime(4, 14, 7))); } - dt1 = QDateTime(QDate(2013, 1, 1), QTime(0, 0), Qt::OffsetFromUTC, 60 * 60); + dt1 = QDateTime(QDate(2013, 1, 1), QTime(0, 0), QTimeZone::fromSecondsAheadOfUtc(60 * 60)); dt1.setSecsSinceEpoch(123456); - QCOMPARE(dt1, QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36), Qt::UTC)); + QCOMPARE(dt1, QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36), UTC)); QCOMPARE(dt1.timeSpec(), Qt::OffsetFromUTC); QCOMPARE(dt1.offsetFromUtc(), 60 * 60); // Only testing UTC; see fromSecsSinceEpoch() for fuller test. - dt1.setTimeSpec(Qt::UTC); + dt1.setTimeZone(UTC); const qint64 maxSeconds = std::numeric_limits::max() / 1000; dt1.setSecsSinceEpoch(maxSeconds); QVERIFY(dt1.isValid()); @@ -677,55 +681,55 @@ void tst_QDateTime::setMSecsSinceEpoch_data() QTest::newRow("zero") << Q_INT64_C(0) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC) + << QDateTime(QDate(1970, 1, 1), QTime(0, 0), UTC) << QDateTime(QDate(1970, 1, 1), QTime(1, 0)); QTest::newRow("+1ms") << Q_INT64_C(+1) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0, 1), Qt::UTC) + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0, 1), UTC) << QDateTime(QDate(1970, 1, 1), QTime(1, 0, 0, 1)); QTest::newRow("+1s") << Q_INT64_C(+1000) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), Qt::UTC) + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), UTC) << QDateTime(QDate(1970, 1, 1), QTime(1, 0, 1)); QTest::newRow("-1ms") << Q_INT64_C(-1) - << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59, 999), Qt::UTC) + << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59, 999), UTC) << QDateTime(QDate(1970, 1, 1), QTime(0, 59, 59, 999)); QTest::newRow("-1s") << Q_INT64_C(-1000) - << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), Qt::UTC) + << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), UTC) << QDateTime(QDate(1970, 1, 1), QTime(0, 59, 59)); QTest::newRow("123456789") << Q_INT64_C(123456789) - << QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36, 789), Qt::UTC) + << QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36, 789), UTC) << QDateTime(QDate(1970, 1, 2), QTime(11, 17, 36, 789)); QTest::newRow("-123456789") << Q_INT64_C(-123456789) - << QDateTime(QDate(1969, 12, 30), QTime(13, 42, 23, 211), Qt::UTC) + << QDateTime(QDate(1969, 12, 30), QTime(13, 42, 23, 211), UTC) << QDateTime(QDate(1969, 12, 30), QTime(14, 42, 23, 211)); QTest::newRow("post-32-bit-time_t") << (Q_INT64_C(1000) << 32) - << QDateTime(QDate(2106, 2, 7), QTime(6, 28, 16), Qt::UTC) + << QDateTime(QDate(2106, 2, 7), QTime(6, 28, 16), UTC) << QDateTime(QDate(2106, 2, 7), QTime(7, 28, 16)); QTest::newRow("very-large") << (Q_INT64_C(123456) << 32) - << QDateTime(QDate(18772, 8, 15), QTime(1, 8, 14, 976), Qt::UTC) + << QDateTime(QDate(18772, 8, 15), QTime(1, 8, 14, 976), UTC) << QDateTime(QDate(18772, 8, 15), QTime(3, 8, 14, 976)); QTest::newRow("old min (Tue Nov 25 00:00:00 -4714)") << Q_INT64_C(-210866716800000) - << QDateTime(QDate::fromJulianDay(1), QTime(0, 0), Qt::UTC) + << QDateTime(QDate::fromJulianDay(1), QTime(0, 0), UTC) << QDateTime(QDate::fromJulianDay(1), QTime(1, 0)).addSecs(preZoneFix); QTest::newRow("old max (Tue Jun 3 21:59:59 5874898)") << Q_INT64_C(185331720376799999) - << QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(21, 59, 59, 999), Qt::UTC) + << QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(21, 59, 59, 999), UTC) << QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(23, 59, 59, 999)); QTest::newRow("min") << std::numeric_limits::min() - << QDateTime(QDate(-292275056, 5, 16), QTime(16, 47, 4, 192), Qt::UTC) + << QDateTime(QDate(-292275056, 5, 16), QTime(16, 47, 4, 192), UTC) << QDateTime(QDate(-292275056, 5, 16), QTime(17, 47, 4, 192).addSecs(preZoneFix)); QTest::newRow("max") << std::numeric_limits::max() - << QDateTime(QDate(292278994, 8, 17), QTime(7, 12, 55, 807), Qt::UTC) + << QDateTime(QDate(292278994, 8, 17), QTime(7, 12, 55, 807), UTC) << QDateTime(QDate(292278994, 8, 17), QTime(9, 12, 55, 807)); } @@ -736,7 +740,7 @@ void tst_QDateTime::setMSecsSinceEpoch() QFETCH(QDateTime, cet); QDateTime dt; - dt.setTimeSpec(Qt::UTC); + dt.setTimeZone(UTC); dt.setMSecsSinceEpoch(msecs); QCOMPARE(dt, utc); @@ -745,14 +749,14 @@ void tst_QDateTime::setMSecsSinceEpoch() QCOMPARE(dt.timeSpec(), Qt::UTC); { - QDateTime dt1 = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC); + QDateTime dt1 = QDateTime::fromMSecsSinceEpoch(msecs, UTC); QCOMPARE(dt1, utc); QCOMPARE(dt1.date(), utc.date()); QCOMPARE(dt1.time(), utc.time()); QCOMPARE(dt1.timeSpec(), Qt::UTC); } { - QDateTime dt1(utc.date(), utc.time(), Qt::UTC); + QDateTime dt1(utc.date(), utc.time(), UTC); QCOMPARE(dt1, utc); QCOMPARE(dt1.date(), utc.date()); QCOMPARE(dt1.time(), utc.time()); @@ -778,7 +782,7 @@ void tst_QDateTime::setMSecsSinceEpoch() // Test converting from LocalTime to UTC back to LocalTime. QDateTime localDt; - localDt.setTimeSpec(Qt::LocalTime); + localDt.setTimeZone(QTimeZone::LocalTime); localDt.setMSecsSinceEpoch(msecs); QCOMPARE(localDt, utc); @@ -808,16 +812,16 @@ void tst_QDateTime::setMSecsSinceEpoch() QCOMPARE(dt.toMSecsSinceEpoch(), msecs); QCOMPARE(qint64(dt.toSecsSinceEpoch()), msecs / 1000); - QDateTime reference(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime reference(QDate(1970, 1, 1), QTime(0, 0), UTC); QCOMPARE(dt, reference.addMSecs(msecs)); // Tests that we correctly recognize when we fall off the extremities: if (msecs == std::numeric_limits::max()) { - QDateTime off(QDate(1970, 1, 1).startOfDay(Qt::OffsetFromUTC, 1)); + QDateTime off(QDate(1970, 1, 1).startOfDay(QTimeZone::fromSecondsAheadOfUtc(1))); off.setMSecsSinceEpoch(msecs); QVERIFY(!off.isValid()); } else if (msecs == std::numeric_limits::min()) { - QDateTime off(QDate(1970, 1, 1).startOfDay(Qt::OffsetFromUTC, -1)); + QDateTime off(QDate(1970, 1, 1).startOfDay(QTimeZone::fromSecondsAheadOfUtc(-1))); off.setMSecsSinceEpoch(msecs); QVERIFY(!off.isValid()); } @@ -838,8 +842,9 @@ void tst_QDateTime::fromMSecsSinceEpoch() using Bound = std::numeric_limits; QDateTime dtLocal = QDateTime::fromMSecsSinceEpoch(msecs); - QDateTime dtUtc = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC); - QDateTime dtOffset = QDateTime::fromMSecsSinceEpoch(msecs, Qt::OffsetFromUTC, 60*60); + QDateTime dtUtc = QDateTime::fromMSecsSinceEpoch(msecs, UTC); + QDateTime dtOffset + = QDateTime::fromMSecsSinceEpoch(msecs, QTimeZone::fromSecondsAheadOfUtc(60 * 60)); // LocalTime will overflow for "min" or "max" tests, depending on whether // you're East or West of Greenwich. In UTC, we won't overflow. If we're // actually west of Greenwich but (e.g. Europe/Madrid) our zone claims east, @@ -881,7 +886,7 @@ void tst_QDateTime::fromMSecsSinceEpoch() if (msecs != Bound::max()) QCOMPARE(qint64(dtOffset.toSecsSinceEpoch()), msecs / 1000); - QDateTime reference(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime reference(QDate(1970, 1, 1), QTime(0, 0), UTC); if (!localOverflow) QCOMPARE(dtLocal, reference.addMSecs(msecs)); QCOMPARE(dtUtc, reference.addMSecs(msecs)); @@ -893,13 +898,13 @@ void tst_QDateTime::fromSecsSinceEpoch() { // Compare setSecsSinceEpoch() const qint64 maxSeconds = std::numeric_limits::max() / 1000; - const QDateTime early = QDateTime::fromSecsSinceEpoch(-maxSeconds, Qt::UTC); - const QDateTime late = QDateTime::fromSecsSinceEpoch(maxSeconds, Qt::UTC); + const QDateTime early = QDateTime::fromSecsSinceEpoch(-maxSeconds, UTC); + const QDateTime late = QDateTime::fromSecsSinceEpoch(maxSeconds, UTC); QVERIFY(late.isValid()); - QVERIFY(!QDateTime::fromSecsSinceEpoch(maxSeconds + 1, Qt::UTC).isValid()); + QVERIFY(!QDateTime::fromSecsSinceEpoch(maxSeconds + 1, UTC).isValid()); QVERIFY(early.isValid()); - QVERIFY(!QDateTime::fromSecsSinceEpoch(-maxSeconds - 1, Qt::UTC).isValid()); + QVERIFY(!QDateTime::fromSecsSinceEpoch(-maxSeconds - 1, UTC).isValid()); // Local time: need to adjust for its zone offset const qint64 last = maxSeconds - qMax(late.addYears(-1).toLocalTime().offsetFromUtc(), 0); @@ -910,10 +915,14 @@ void tst_QDateTime::fromSecsSinceEpoch() QVERIFY(!QDateTime::fromSecsSinceEpoch(first - 1).isValid()); // Use an offset for which .toUTC()'s return would flip the validity: - QVERIFY(QDateTime::fromSecsSinceEpoch(maxSeconds - 7200, Qt::OffsetFromUTC, 7200).isValid()); - QVERIFY(!QDateTime::fromSecsSinceEpoch(maxSeconds - 7199, Qt::OffsetFromUTC, 7200).isValid()); - QVERIFY(QDateTime::fromSecsSinceEpoch(7200 - maxSeconds, Qt::OffsetFromUTC, -7200).isValid()); - QVERIFY(!QDateTime::fromSecsSinceEpoch(7199 - maxSeconds, Qt::OffsetFromUTC, -7200).isValid()); + QVERIFY(QDateTime::fromSecsSinceEpoch(maxSeconds - 7200, + QTimeZone::fromSecondsAheadOfUtc(7200)).isValid()); + QVERIFY(!QDateTime::fromSecsSinceEpoch(maxSeconds - 7199, + QTimeZone::fromSecondsAheadOfUtc(7200)).isValid()); + QVERIFY(QDateTime::fromSecsSinceEpoch(7200 - maxSeconds, + QTimeZone::fromSecondsAheadOfUtc(-7200)).isValid()); + QVERIFY(!QDateTime::fromSecsSinceEpoch(7199 - maxSeconds, + QTimeZone::fromSecondsAheadOfUtc(-7200)).isValid()); #if QT_CONFIG(timezone) // As for offset, use zones each side of UTC: @@ -936,23 +945,23 @@ void tst_QDateTime::toString_isoDate_data() << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34)) << Qt::ISODate << QString("1978-11-09T13:28:34"); QTest::newRow("UTC") - << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), Qt::UTC) + << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), UTC) << Qt::ISODate << QString("1978-11-09T13:28:34Z"); QDateTime dt(QDate(1978, 11, 9), QTime(13, 28, 34)); - dt.setOffsetFromUtc(19800); + dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(19800)); QTest::newRow("positive OffsetFromUTC") << dt << Qt::ISODate << QString("1978-11-09T13:28:34+05:30"); - dt.setOffsetFromUtc(-7200); + dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-7200)); QTest::newRow("negative OffsetFromUTC") << dt << Qt::ISODate << QString("1978-11-09T13:28:34-02:00"); - dt.setOffsetFromUtc(-900); + dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-900)); QTest::newRow("negative non-integral OffsetFromUTC") << dt << Qt::ISODate << QString("1978-11-09T13:28:34-00:15"); QTest::newRow("invalid") // ISODate < 2019 doesn't allow -ve year numbers; QTBUG-91070 - << QDateTime(QDate(-1, 11, 9), QTime(13, 28, 34), Qt::UTC) + << QDateTime(QDate(-1, 11, 9), QTime(13, 28, 34), UTC) << Qt::ISODate << QString(); QTest::newRow("without-ms") << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34, 20)) @@ -989,7 +998,7 @@ void tst_QDateTime::toString_isoDate() void tst_QDateTime::toString_isoDate_extra() { - QDateTime dt = QDateTime::fromMSecsSinceEpoch(0, Qt::UTC); + QDateTime dt = QDateTime::fromMSecsSinceEpoch(0, UTC); QCOMPARE(dt.toString(Qt::ISODate), QLatin1String("1970-01-01T00:00:00Z")); #if QT_CONFIG(timezone) QTimeZone PST("America/Vancouver"); @@ -1020,13 +1029,13 @@ void tst_QDateTime::toString_textDate_data() // ### Qt 7 GMT: change to UTC - see matching QDateTime::fromString() comment QTest::newRow("localtime") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3)) << wednesdayJanuary + QString(" 2 01:02:03 2013"); - QTest::newRow("utc") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3), Qt::UTC) + QTest::newRow("utc") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3), UTC) << wednesdayJanuary + QString(" 2 01:02:03 2013 GMT"); - QTest::newRow("offset+") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3), Qt::OffsetFromUTC, - 10 * 60 * 60) + QTest::newRow("offset+") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3), + QTimeZone::fromSecondsAheadOfUtc(10 * 60 * 60)) << wednesdayJanuary + QString(" 2 01:02:03 2013 GMT+1000"); - QTest::newRow("offset-") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3), Qt::OffsetFromUTC, - -10 * 60 * 60) + QTest::newRow("offset-") << QDateTime(QDate(2013, 1, 2), QTime(1, 2, 3), + QTimeZone::fromSecondsAheadOfUtc(-10 * 60 * 60)) << wednesdayJanuary + QString(" 2 01:02:03 2013 GMT-1000"); QTest::newRow("invalid") << QDateTime() << QString(""); @@ -1058,7 +1067,7 @@ void tst_QDateTime::toString_textDate_extra() }; QDateTime dt = QDateTime::fromMSecsSinceEpoch(0); QVERIFY(!endsWithGmt(dt)); - dt = QDateTime::fromMSecsSinceEpoch(0, Qt::UTC).toLocalTime(); + dt = QDateTime::fromMSecsSinceEpoch(0, UTC).toLocalTime(); QVERIFY(!endsWithGmt(dt)); #if QT_CONFIG(timezone) @@ -1091,7 +1100,7 @@ void tst_QDateTime::toString_textDate_extra() else QCOMPARE(dt.toString(), QLatin1String("Thu Jan 1 00:00:00 1970")); #endif - dt = QDateTime::fromMSecsSinceEpoch(0, Qt::UTC); + dt = QDateTime::fromMSecsSinceEpoch(0, UTC); QVERIFY(endsWithGmt(dt)); } @@ -1106,22 +1115,22 @@ void tst_QDateTime::toString_rfcDate_data() << QString("09 Nov 1978 13:28:34 +0100"); } QTest::newRow("UTC") - << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), Qt::UTC) + << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), UTC) << QString("09 Nov 1978 13:28:34 +0000"); QDateTime dt(QDate(1978, 11, 9), QTime(13, 28, 34)); - dt.setOffsetFromUtc(19800); + dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(19800)); QTest::newRow("positive OffsetFromUTC") << dt << QString("09 Nov 1978 13:28:34 +0530"); - dt.setOffsetFromUtc(-7200); + dt.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-7200)); QTest::newRow("negative OffsetFromUTC") << dt << QString("09 Nov 1978 13:28:34 -0200"); QTest::newRow("invalid") - << QDateTime(QDate(1978, 13, 9), QTime(13, 28, 34), Qt::UTC) + << QDateTime(QDate(1978, 13, 9), QTime(13, 28, 34), UTC) << QString(); QTest::newRow("999 milliseconds UTC") - << QDateTime(QDate(2000, 1, 1), QTime(13, 28, 34, 999), Qt::UTC) + << QDateTime(QDate(2000, 1, 1), QTime(13, 28, 34, 999), UTC) << QString("01 Jan 2000 13:28:34 +0000"); } @@ -1154,7 +1163,7 @@ void tst_QDateTime::toString_strformat() // Most tests are in QLocale, just test that the api works. QDate testDate(2013, 1, 1); QTime testTime(1, 2, 3, 456); - QDateTime testDateTime(testDate, testTime, Qt::UTC); + QDateTime testDateTime(testDate, testTime, UTC); QCOMPARE(testDate.toString("yyyy-MM-dd"), QString("2013-01-01")); QCOMPARE(testTime.toString("hh:mm:ss"), QString("01:02:03")); QCOMPARE(testTime.toString("hh:mm:ss.zz"), QString("01:02:03.456")); @@ -1205,7 +1214,7 @@ void tst_QDateTime::addDays() } // Test preserves TimeSpec - QDateTime dt1(QDate(2013, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime dt1(QDate(2013, 1, 1), QTime(0, 0), UTC); QDateTime dt2 = dt1.addDays(2); QCOMPARE(dt2.date(), QDate(2013, 1, 3)); QCOMPARE(dt2.time(), QTime(0, 0)); @@ -1237,10 +1246,10 @@ void tst_QDateTime::addDays() #endif // Test last UTC second of 1969 *is* valid (despite being time_t(-1)) - dt1 = QDateTime(QDate(1969, 12, 30), QTime(23, 59, 59), Qt::UTC).toLocalTime().addDays(1); + dt1 = QDateTime(QDate(1969, 12, 30), QTime(23, 59, 59), UTC).toLocalTime().addDays(1); QVERIFY(dt1.isValid()); QCOMPARE(dt1.toSecsSinceEpoch(), -1); - dt2 = QDateTime(QDate(1970, 1, 1), QTime(23, 59, 59), Qt::UTC).toLocalTime().addDays(-1); + dt2 = QDateTime(QDate(1970, 1, 1), QTime(23, 59, 59), UTC).toLocalTime().addDays(-1); QVERIFY(dt2.isValid()); QCOMPARE(dt2.toSecsSinceEpoch(), -1); } @@ -1262,7 +1271,7 @@ void tst_QDateTime::addInvalid() offset = bad.addMSecs(73); QVERIFY(offset.isNull()); - QDateTime bound = QDateTime::fromMSecsSinceEpoch(std::numeric_limits::min(), Qt::UTC); + QDateTime bound = QDateTime::fromMSecsSinceEpoch(std::numeric_limits::min(), UTC); QVERIFY(bound.isValid()); offset = bound.addMSecs(-1); QVERIFY(!offset.isValid()); @@ -1341,13 +1350,13 @@ void tst_QDateTime::addMonths() QCOMPARE(end.time(), testTime); QCOMPARE(end.timeSpec(), Qt::LocalTime); - start = QDateTime(testDate, testTime, Qt::UTC); + start = QDateTime(testDate, testTime, UTC); end = start.addMonths(months); QCOMPARE(end.date(), resultDate); QCOMPARE(end.time(), testTime); QCOMPARE(end.timeSpec(), Qt::UTC); - start = QDateTime(testDate, testTime, Qt::OffsetFromUTC, 60 * 60); + start = QDateTime(testDate, testTime, QTimeZone::fromSecondsAheadOfUtc(60 * 60)); end = start.addMonths(months); QCOMPARE(end.date(), resultDate); QCOMPARE(end.time(), testTime); @@ -1393,13 +1402,13 @@ void tst_QDateTime::addYears() QCOMPARE(end.time(), testTime); QCOMPARE(end.timeSpec(), Qt::LocalTime); - start = QDateTime(startDate, testTime, Qt::UTC); + start = QDateTime(startDate, testTime, UTC); end = start.addYears(years1).addYears(years2); QCOMPARE(end.date(), resultDate); QCOMPARE(end.time(), testTime); QCOMPARE(end.timeSpec(), Qt::UTC); - start = QDateTime(startDate, testTime, Qt::OffsetFromUTC, 60 * 60); + start = QDateTime(startDate, testTime, QTimeZone::fromSecondsAheadOfUtc(60 * 60)); end = start.addYears(years1).addYears(years2); QCOMPARE(end.date(), resultDate); QCOMPARE(end.time(), testTime); @@ -1418,35 +1427,35 @@ void tst_QDateTime::addMSecs_data() const qint64 daySecs(86400); QTest::newRow("utc0") - << QDateTime(QDate(2004, 1, 1), standardTime, Qt::UTC) << daySecs - << QDateTime(QDate(2004, 1, 2), standardTime, Qt::UTC); + << QDateTime(QDate(2004, 1, 1), standardTime, UTC) << daySecs + << QDateTime(QDate(2004, 1, 2), standardTime, UTC); QTest::newRow("utc1") - << QDateTime(QDate(2004, 1, 1), standardTime, Qt::UTC) << (daySecs * 185) - << QDateTime(QDate(2004, 7, 4), standardTime, Qt::UTC); + << QDateTime(QDate(2004, 1, 1), standardTime, UTC) << (daySecs * 185) + << QDateTime(QDate(2004, 7, 4), standardTime, UTC); QTest::newRow("utc2") - << QDateTime(QDate(2004, 1, 1), standardTime, Qt::UTC) << (daySecs * 366) - << QDateTime(QDate(2005, 1, 1), standardTime, Qt::UTC); + << QDateTime(QDate(2004, 1, 1), standardTime, UTC) << (daySecs * 366) + << QDateTime(QDate(2005, 1, 1), standardTime, UTC); QTest::newRow("utc3") - << QDateTime(QDate(1760, 1, 1), standardTime, Qt::UTC) << daySecs - << QDateTime(QDate(1760, 1, 2), standardTime, Qt::UTC); + << QDateTime(QDate(1760, 1, 1), standardTime, UTC) << daySecs + << QDateTime(QDate(1760, 1, 2), standardTime, UTC); QTest::newRow("utc4") - << QDateTime(QDate(1760, 1, 1), standardTime, Qt::UTC) << (daySecs * 185) - << QDateTime(QDate(1760, 7, 4), standardTime, Qt::UTC); + << QDateTime(QDate(1760, 1, 1), standardTime, UTC) << (daySecs * 185) + << QDateTime(QDate(1760, 7, 4), standardTime, UTC); QTest::newRow("utc5") - << QDateTime(QDate(1760, 1, 1), standardTime, Qt::UTC) << (daySecs * 366) - << QDateTime(QDate(1761, 1, 1), standardTime, Qt::UTC); + << QDateTime(QDate(1760, 1, 1), standardTime, UTC) << (daySecs * 366) + << QDateTime(QDate(1761, 1, 1), standardTime, UTC); QTest::newRow("utc6") - << QDateTime(QDate(4000, 1, 1), standardTime, Qt::UTC) << daySecs - << QDateTime(QDate(4000, 1, 2), standardTime, Qt::UTC); + << QDateTime(QDate(4000, 1, 1), standardTime, UTC) << daySecs + << QDateTime(QDate(4000, 1, 2), standardTime, UTC); QTest::newRow("utc7") - << QDateTime(QDate(4000, 1, 1), standardTime, Qt::UTC) << (daySecs * 185) - << QDateTime(QDate(4000, 7, 4), standardTime, Qt::UTC); + << QDateTime(QDate(4000, 1, 1), standardTime, UTC) << (daySecs * 185) + << QDateTime(QDate(4000, 7, 4), standardTime, UTC); QTest::newRow("utc8") - << QDateTime(QDate(4000, 1, 1), standardTime, Qt::UTC) << (daySecs * 366) - << QDateTime(QDate(4001, 1, 1), standardTime, Qt::UTC); + << QDateTime(QDate(4000, 1, 1), standardTime, UTC) << (daySecs * 366) + << QDateTime(QDate(4001, 1, 1), standardTime, UTC); QTest::newRow("utc9") - << QDateTime(QDate(4000, 1, 1), standardTime, Qt::UTC) << qint64(0) - << QDateTime(QDate(4000, 1, 1), standardTime, Qt::UTC); + << QDateTime(QDate(4000, 1, 1), standardTime, UTC) << qint64(0) + << QDateTime(QDate(4000, 1, 1), standardTime, UTC); if (zoneIsCET) { QTest::newRow("cet0") @@ -1483,42 +1492,42 @@ void tst_QDateTime::addMSecs_data() // Year sign change QTest::newRow("toNegative") - << QDateTime(QDate(1, 1, 1), QTime(0, 0), Qt::UTC) << qint64(-1) - << QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59), Qt::UTC); + << QDateTime(QDate(1, 1, 1), QTime(0, 0), UTC) << qint64(-1) + << QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59), UTC); QTest::newRow("toPositive") - << QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59), Qt::UTC) << qint64(1) - << QDateTime(QDate(1, 1, 1), QTime(0, 0), Qt::UTC); + << QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59), UTC) << qint64(1) + << QDateTime(QDate(1, 1, 1), QTime(0, 0), UTC); QTest::newRow("invalid") << QDateTime() << qint64(1) << QDateTime(); // Check Offset details are preserved QTest::newRow("offset0") - << QDateTime(QDate(2013, 1, 1), QTime(1, 2, 3), Qt::OffsetFromUTC, 60 * 60) + << QDateTime(QDate(2013, 1, 1), QTime(1, 2, 3), QTimeZone::fromSecondsAheadOfUtc(60 * 60)) << qint64(60 * 60) - << QDateTime(QDate(2013, 1, 1), QTime(2, 2, 3), Qt::OffsetFromUTC, 60 * 60); + << QDateTime(QDate(2013, 1, 1), QTime(2, 2, 3), QTimeZone::fromSecondsAheadOfUtc(60 * 60)); // Check last second of 1969 QTest::newRow("epoch-1s-utc") - << QDateTime(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC) << qint64(-1) - << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), Qt::UTC); + << QDateTime(QDate(1970, 1, 1), QTime(0, 0), UTC) << qint64(-1) + << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), UTC); QTest::newRow("epoch-1s-local") << QDateTime(QDate(1970, 1, 1), QTime(0, 0)) << qint64(-1) << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59)); QTest::newRow("epoch-1s-utc-as-local") - << QDate(1970, 1, 1).startOfDay(Qt::UTC).toLocalTime() << qint64(-1) - << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), Qt::UTC).toLocalTime(); + << QDate(1970, 1, 1).startOfDay(UTC).toLocalTime() << qint64(-1) + << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), UTC).toLocalTime(); // Overflow and Underflow const qint64 maxSeconds = std::numeric_limits::max() / 1000; QTest::newRow("after-last") - << QDateTime::fromSecsSinceEpoch(maxSeconds, Qt::UTC) << qint64(1) << QDateTime(); + << QDateTime::fromSecsSinceEpoch(maxSeconds, UTC) << qint64(1) << QDateTime(); QTest::newRow("to-last") - << QDateTime::fromSecsSinceEpoch(maxSeconds - 1, Qt::UTC) << qint64(1) - << QDateTime::fromSecsSinceEpoch(maxSeconds, Qt::UTC); + << QDateTime::fromSecsSinceEpoch(maxSeconds - 1, UTC) << qint64(1) + << QDateTime::fromSecsSinceEpoch(maxSeconds, UTC); QTest::newRow("before-first") - << QDateTime::fromSecsSinceEpoch(-maxSeconds, Qt::UTC) << qint64(-1) << QDateTime(); + << QDateTime::fromSecsSinceEpoch(-maxSeconds, UTC) << qint64(-1) << QDateTime(); QTest::newRow("to-first") - << QDateTime::fromSecsSinceEpoch(1 - maxSeconds, Qt::UTC) << qint64(-1) - << QDateTime::fromSecsSinceEpoch(-maxSeconds, Qt::UTC); + << QDateTime::fromSecsSinceEpoch(1 - maxSeconds, UTC) << qint64(-1) + << QDateTime::fromSecsSinceEpoch(-maxSeconds, UTC); } void tst_QDateTime::addSecs_data() @@ -1528,9 +1537,9 @@ void tst_QDateTime::addSecs_data() const qint64 maxSeconds = std::numeric_limits::max() / 1000; // Results would be representable, but the step isn't QTest::newRow("leap-up") - << QDateTime::fromSecsSinceEpoch(-1, Qt::UTC) << 1 + maxSeconds << QDateTime(); + << QDateTime::fromSecsSinceEpoch(-1, UTC) << 1 + maxSeconds << QDateTime(); QTest::newRow("leap-down") - << QDateTime::fromSecsSinceEpoch(1, Qt::UTC) << -1 - maxSeconds << QDateTime(); + << QDateTime::fromSecsSinceEpoch(1, UTC) << -1 - maxSeconds << QDateTime(); } void tst_QDateTime::addSecs() @@ -1601,58 +1610,58 @@ void tst_QDateTime::toTimeSpec_data() QTime localDaylightTime(6, 20, 30); QTest::newRow("winter1") - << QDateTime(QDate(2004, 1, 1), utcTime, Qt::UTC) + << QDateTime(QDate(2004, 1, 1), utcTime, UTC) << QDateTime(QDate(2004, 1, 1), localStandardTime); QTest::newRow("winter2") - << QDateTime(QDate(2004, 2, 29), utcTime, Qt::UTC) + << QDateTime(QDate(2004, 2, 29), utcTime, UTC) << QDateTime(QDate(2004, 2, 29), localStandardTime); QTest::newRow("winter3") - << QDateTime(QDate(1760, 2, 29), utcTime, Qt::UTC) + << QDateTime(QDate(1760, 2, 29), utcTime, UTC) << QDateTime(QDate(1760, 2, 29), localStandardTime.addSecs(preZoneFix)); QTest::newRow("winter4") - << QDateTime(QDate(6000, 2, 29), utcTime, Qt::UTC) + << QDateTime(QDate(6000, 2, 29), utcTime, UTC) << QDateTime(QDate(6000, 2, 29), localStandardTime); // Test mktime boundaries (1970 - 2038) and adjustDate(). QTest::newRow("1969/12/31 23:00 UTC") - << QDateTime(QDate(1969, 12, 31), QTime(23, 0), Qt::UTC) - << QDate(1970, 1, 1).startOfDay(); + << QDateTime(QDate(1969, 12, 31), QTime(23, 0), UTC) + << QDateTime(QDate(1970, 1, 1), QTime(0, 0)); QTest::newRow("1969/12/31 23:59:59 UTC") - << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), Qt::UTC) + << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), UTC) << QDateTime(QDate(1970, 1, 1), QTime(0, 59, 59)); QTest::newRow("2037/12/31 23:00 UTC") - << QDateTime(QDate(2037, 12, 31), QTime(23, 0), Qt::UTC) - << QDate(2038, 1, 1).startOfDay(); + << QDateTime(QDate(2037, 12, 31), QTime(23, 0), UTC) + << QDateTime(QDate(2038, 1, 1), QTime(0, 0)); QTest::newRow("-271821/4/20 00:00 UTC (JavaScript min date, start of day)") - << QDateTime(QDate(-271821, 4, 20), QTime(0, 0), Qt::UTC) + << QDateTime(QDate(-271821, 4, 20), QTime(0, 0), UTC) << QDateTime(QDate(-271821, 4, 20), QTime(1, 0)).addSecs(preZoneFix); QTest::newRow("-271821/4/20 23:00 UTC (JavaScript min date, end of day)") - << QDateTime(QDate(-271821, 4, 20), QTime(23, 0), Qt::UTC) + << QDateTime(QDate(-271821, 4, 20), QTime(23, 0), UTC) << QDateTime(QDate(-271821, 4, 21), QTime(0, 0)).addSecs(preZoneFix); if (zoneIsCET) { QTest::newRow("summer1") - << QDateTime(QDate(2004, 6, 30), utcTime, Qt::UTC) + << QDateTime(QDate(2004, 6, 30), utcTime, UTC) << QDateTime(QDate(2004, 6, 30), localDaylightTime); QTest::newRow("summer2") - << QDateTime(QDate(1760, 6, 30), utcTime, Qt::UTC) + << QDateTime(QDate(1760, 6, 30), utcTime, UTC) << QDateTime(QDate(1760, 6, 30), localStandardTime.addSecs(preZoneFix)); QTest::newRow("summer3") - << QDateTime(QDate(4000, 6, 30), utcTime, Qt::UTC) + << QDateTime(QDate(4000, 6, 30), utcTime, UTC) << QDateTime(QDate(4000, 6, 30), localDaylightTime); QTest::newRow("275760/9/23 00:00 UTC (JavaScript max date, start of day)") - << QDate(275760, 9, 23).startOfDay(Qt::UTC) + << QDate(275760, 9, 23).startOfDay(UTC) << QDateTime(QDate(275760, 9, 23), QTime(2, 0)); QTest::newRow("275760/9/23 22:00 UTC (JavaScript max date, end of day)") - << QDateTime(QDate(275760, 9, 23), QTime(22, 0), Qt::UTC) + << QDateTime(QDate(275760, 9, 23), QTime(22, 0), UTC) << QDate(275760, 9, 24).startOfDay(); } QTest::newRow("msec") - << QDateTime(QDate(4000, 6, 30), utcTime.addMSecs(1), Qt::UTC) + << QDateTime(QDate(4000, 6, 30), utcTime.addMSecs(1), UTC) << QDateTime(QDate(4000, 6, 30), localDaylightTime.addMSecs(1)); } @@ -2066,7 +2075,7 @@ void tst_QDateTime::daylightSavingsTimeChange() // Now use the result of a UTC -> LocalTime conversion dt = outDST.startOfDay().toUTC(); - dt = QDateTime(dt.date(), dt.time(), Qt::UTC).toLocalTime(); + dt = QDateTime(dt.date(), dt.time(), UTC).toLocalTime(); QCOMPARE(dt, QDateTime(outDST, QTime(0, 0))); // using addDays: @@ -2204,7 +2213,7 @@ void tst_QDateTime::springForward() // Repeat, but getting there via .toTimeZone(): QDateTime detour = QDateTime(day.addDays(-step), time.addSecs(-60 * adjust), - QTimeZone::UTC).toTimeZone(zone); + UTC).toTimeZone(zone); QCOMPARE(detour.time(), time); detour = detour.addDays(step); // Insist on consistency: @@ -2225,14 +2234,14 @@ void tst_QDateTime::operator_eqeq_data() QDateTime dateTime1a = dateTime1.addMSecs(1); QDateTime dateTime2(QDate(2012, 20, 6), QTime(14, 33, 2, 500)); // Invalid QDateTime dateTime2a = dateTime2.addMSecs(-1); // Still invalid - QDateTime dateTime3(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC); // UTC epoch + QDateTime dateTime3(QDate(1970, 1, 1), QTime(0, 0), UTC); // UTC epoch QDateTime dateTime3a = dateTime3.addDays(1); QDateTime dateTime3b = dateTime3.addDays(-1); // Ensure that different times may be equal when considering timezone. QDateTime dateTime3c(dateTime3.addSecs(3600)); - dateTime3c.setOffsetFromUtc(3600); + dateTime3c.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(3600)); QDateTime dateTime3d(dateTime3.addSecs(-3600)); - dateTime3d.setOffsetFromUtc(-3600); + dateTime3d.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-3600)); QDateTime dateTime3e(dateTime3.date(), dateTime3.time()); // Local time's epoch QTest::newRow("data0") << dateTime1 << dateTime1 << true << false; @@ -2259,7 +2268,7 @@ void tst_QDateTime::operator_eqeq_data() if (zoneIsCET) { QTest::newRow("data14") << QDateTime(QDate(2004, 1, 2), QTime(2, 2, 3)) - << QDateTime(QDate(2004, 1, 2), QTime(1, 2, 3), Qt::UTC) << true << true; + << QDateTime(QDate(2004, 1, 2), QTime(1, 2, 3), UTC) << true << true; QTest::newRow("local-fall-back") // Sun, 31 Oct 2004, 02:30, both ways round: << QDateTime::fromMSecsSinceEpoch(Q_INT64_C(1099186200000)) << QDateTime::fromMSecsSinceEpoch(Q_INT64_C(1099182600000)) @@ -2390,7 +2399,7 @@ void tst_QDateTime::operator_insert_extract() if (dataStreamVersion < QDataStream::Qt_4_0) { // Versions lower than Qt 4 don't serialise the timeSpec, instead // assuming that everything is LocalTime. - deserialised.setTimeSpec(Qt::UTC); + deserialised.setTimeZone(UTC); } // Qt 4.* versions do serialise the timeSpec, so we only need to convert from UTC here. deserialised = deserialised.toLocalTime(); @@ -2408,7 +2417,7 @@ void tst_QDateTime::operator_insert_extract() qint8 deserialisedSpec; if (dataStreamVersion >= QDataStream::Qt_4_0) dataStream >> deserialisedSpec; - deserialised = QDateTime(deserialisedDate, deserialisedTime, Qt::UTC); + deserialised = QDateTime(deserialisedDate, deserialisedTime, UTC); QCOMPARE(deserialised.toLocalTime(), deserialised); const auto isLocalTime = [](qint8 spec) -> bool { // The spec is in fact a QDateTimePrivate::Spec, not Qt::TimeSpec; @@ -2418,7 +2427,7 @@ void tst_QDateTime::operator_insert_extract() return decoded != QDateTimePrivate::UTC && decoded != QDateTimePrivate::OffsetFromUTC; }; if (dataStreamVersion >= QDataStream::Qt_4_0 && isLocalTime(deserialisedSpec)) - deserialised = deserialised.toLocalTime(); + deserialised = deserialised.toTimeZone(QTimeZone::LocalTime); // Ensure local time is still correct. QCOMPARE(deserialised, expectedLocalTime); // Sanity check UTC times. @@ -2471,24 +2480,24 @@ void tst_QDateTime::fromStringDateFormat_data() QTest::newRow("text bad offset") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 UTC+foo") << Qt::TextDate << QDateTime(); QTest::newRow("text UTC early") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 UTC") - << Qt::TextDate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << Qt::TextDate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); QTest::newRow("text UTC-3 early") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 UTC-0300") - << Qt::TextDate << QDateTime(QDate(1970, 1, 1), QTime(3, 12, 34), Qt::UTC); + << Qt::TextDate << QDateTime(QDate(1970, 1, 1), QTime(3, 12, 34), UTC); QTest::newRow("text UTC+3 early") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 UTC+0300") - << Qt::TextDate << QDateTime(QDate(1969, 12, 31), QTime(21, 12, 34), Qt::UTC); + << Qt::TextDate << QDateTime(QDate(1969, 12, 31), QTime(21, 12, 34), UTC); QTest::newRow("text UTC+1 early") << QString::fromLatin1("Thu Jan 1 1970 00:12:34 UTC+0100") - << Qt::TextDate << QDateTime(QDate(1969, 12, 31), QTime(23, 12, 34), Qt::UTC); + << Qt::TextDate << QDateTime(QDate(1969, 12, 31), QTime(23, 12, 34), UTC); // We produce use GMT as prefix, so need to parse it: QTest::newRow("text GMT early") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 GMT") << Qt::TextDate - << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); QTest::newRow("text GMT+3 early") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 GMT+0300") << Qt::TextDate - << QDateTime(QDate(1969, 12, 31), QTime(21, 12, 34), Qt::UTC); + << QDateTime(QDate(1969, 12, 31), QTime(21, 12, 34), UTC); // ... and we match (only) it case-insensitively: QTest::newRow("text gmt early") << QString::fromLatin1("Thu Jan 1 00:12:34 1970 gmt") << Qt::TextDate - << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); QTest::newRow("text empty") << QString::fromLatin1("") << Qt::TextDate << QDateTime(); @@ -2584,44 +2593,44 @@ void tst_QDateTime::fromStringDateFormat_data() // Normal usage: QTest::newRow("ISO +01:00") << QString::fromLatin1("1987-02-13T13:24:51+01:00") - << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC); QTest::newRow("ISO +00:01") << QString::fromLatin1("1987-02-13T13:24:51+00:01") - << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(13, 23, 51), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(13, 23, 51), UTC); QTest::newRow("ISO -01:00") << QString::fromLatin1("1987-02-13T13:24:51-01:00") - << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), UTC); QTest::newRow("ISO -00:01") << QString::fromLatin1("1987-02-13T13:24:51-00:01") - << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(13, 25, 51), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(13, 25, 51), UTC); QTest::newRow("ISO +0000") << QString::fromLatin1("1970-01-01T00:12:34+0000") - << Qt::ISODate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); QTest::newRow("ISO +00:00") << QString::fromLatin1("1970-01-01T00:12:34+00:00") - << Qt::ISODate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); QTest::newRow("ISO -03") << QString::fromLatin1("2014-12-15T12:37:09-03") - << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9), UTC); QTest::newRow("ISO zzz-03") << QString::fromLatin1("2014-12-15T12:37:09.745-03") - << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9, 745), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9, 745), UTC); QTest::newRow("ISO -3") << QString::fromLatin1("2014-12-15T12:37:09-3") - << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9), UTC); QTest::newRow("ISO zzz-3") << QString::fromLatin1("2014-12-15T12:37:09.745-3") - << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9, 745), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9, 745), UTC); QTest::newRow("ISO lower-case") << QString::fromLatin1("2005-06-28T07:57:30.002z") - << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), UTC); // No time specified - defaults to Qt::LocalTime. QTest::newRow("ISO data3") << QString::fromLatin1("2002-10-01") << Qt::ISODate << QDate(2002, 10, 1).startOfDay(); // Excess digits in milliseconds, round correctly: QTest::newRow("ISO") << QString::fromLatin1("2005-06-28T07:57:30.0010000000Z") - << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), UTC); QTest::newRow("ISO rounding") << QString::fromLatin1("2005-06-28T07:57:30.0015Z") - << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), UTC); // ... and accept comma as separator: QTest::newRow("ISO with comma 1") << QString::fromLatin1("2005-06-28T07:57:30,0040000000Z") - << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 4), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 4), UTC); QTest::newRow("ISO with comma 2") << QString::fromLatin1("2005-06-28T07:57:30,0015Z") - << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), UTC); QTest::newRow("ISO with comma 3") << QString::fromLatin1("2005-06-28T07:57:30,0014Z") - << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), UTC); QTest::newRow("ISO with comma 4") << QString::fromLatin1("2005-06-28T07:57:30,1Z") - << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 100), Qt::UTC); + << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 100), UTC); QTest::newRow("ISO with comma 5") << QString::fromLatin1("2005-06-28T07:57:30,11") << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 110)); // 24:00:00 Should be next day according to ISO 8601 section 4.2.3. @@ -2715,28 +2724,28 @@ void tst_QDateTime::fromStringDateFormat_data() // Test Qt::RFC2822Date format (RFC 2822). QTest::newRow("RFC 2822 +0100") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100") - << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC); QTest::newRow("RFC 2822 after space +0100") << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100") - << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC); QTest::newRow("RFC 2822 with day +0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 +0100") - << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC); QTest::newRow("RFC 2822 with day after space +0100") << QString::fromLatin1(" Fri, 13 Feb 1987 13:24:51 +0100") - << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC); QTest::newRow("RFC 2822 -0100") << QString::fromLatin1("13 Feb 1987 13:24:51 -0100") - << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), UTC); QTest::newRow("RFC 2822 with day -0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 -0100") - << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), UTC); QTest::newRow("RFC 2822 +0000") << QString::fromLatin1("01 Jan 1970 00:12:34 +0000") - << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); QTest::newRow("RFC 2822 with day +0000") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000") - << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); QTest::newRow("RFC 2822 missing space before +0100") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34+0100") << Qt::RFC2822Date << QDateTime(); // No timezone assume UTC QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34") - << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); // No time specified QTest::newRow("RFC 2822 date only") << QString::fromLatin1("01 Nov 2002") << Qt::RFC2822Date << QDateTime(); @@ -2781,21 +2790,23 @@ void tst_QDateTime::fromStringDateFormat_data() // sure *it's* not what's invalid: QTest::newRow("RFC 2822 (not invalid)") << QString::fromLatin1("01 Jan 2012 08:00:00 +0100") - << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0), UTC); // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive). QTest::newRow("RFC 850 and 1036 +0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100") - << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC); QTest::newRow("RFC 1036 after space +0100") << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100") - << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), UTC); QTest::newRow("RFC 850 and 1036 -0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 -0100") - << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), UTC); + QTest::newRow("RFC 850 and 1036 +0000") << QString::fromLatin1("Thu Jan 01 00:12:34 1970 +0000") + << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); QTest::newRow("RFC 850 and 1036 +0000") << QString::fromLatin1("Thu Jan 01 00:12:34 1970 +0000") - << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); // No timezone assume UTC QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970") - << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), UTC); // No time specified QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002") @@ -2819,7 +2830,7 @@ void tst_QDateTime::fromStringDateFormat_data() // Again, check the text in the "invalid character" tests isn't the source of invalidity: QTest::newRow("RFC 850 and 1036 (not invalid)") << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100") - << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0), Qt::UTC); + << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0), UTC); QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << QDateTime(); } @@ -2872,73 +2883,81 @@ void tst_QDateTime::fromStringStringFormat_data() << QDate(2004, 1, 1).startOfDay(); QTest::newRow("zulu-time-with-z-centisec") << QString("2005-06-28T07:57:30.01Z") << QString("yyyy-MM-ddThh:mm:ss.zt") - << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 10), Qt::UTC); + << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 10), UTC); QTest::newRow("zulu-time-with-zz-decisec") << QString("2005-06-28T07:57:30.1Z") << QString("yyyy-MM-ddThh:mm:ss.zzt") - << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 100), Qt::UTC); + << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 100), UTC); QTest::newRow("zulu-time-with-zzz-centisec") << QString("2005-06-28T07:57:30.01Z") << QString("yyyy-MM-ddThh:mm:ss.zzzt") << QDateTime(); // Invalid because too few digits for zzz QTest::newRow("zulu-time-with-z-millisec") << QString("2005-06-28T07:57:30.001Z") << QString("yyyy-MM-ddThh:mm:ss.zt") - << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 1), Qt::UTC); + << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 1), UTC); QTest::newRow("utc-time-spec-as:UTC+0") << QString("2005-06-28T07:57:30.001UTC+0") << QString("yyyy-MM-ddThh:mm:ss.zt") - << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), Qt::UTC); + << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), UTC); QTest::newRow("utc-time-spec-as:UTC-0") << QString("2005-06-28T07:57:30.001UTC-0") << QString("yyyy-MM-ddThh:mm:ss.zt") - << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), Qt::UTC); + << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), UTC); QTest::newRow("offset-from-utc:UTC+1") << QString("2001-09-13T07:33:01.001 UTC+1") << QString("yyyy-MM-ddThh:mm:ss.z t") - << QDateTime(QDate(2001, 9, 13), QTime(7, 33, 1, 1), Qt::OffsetFromUTC, 3600); + << QDateTime(QDate(2001, 9, 13), QTime(7, 33, 1, 1), + QTimeZone::fromSecondsAheadOfUtc(3600)); QTest::newRow("offset-from-utc:UTC-11:01") << QString("2008-09-13T07:33:01.001 UTC-11:01") << QString("yyyy-MM-ddThh:mm:ss.z t") - << QDateTime(QDate(2008, 9, 13), QTime(7, 33, 1, 1), Qt::OffsetFromUTC, -39660); + << QDateTime(QDate(2008, 9, 13), QTime(7, 33, 1, 1), + QTimeZone::fromSecondsAheadOfUtc(-39660)); QTest::newRow("offset-from-utc:UTC+02:57") << QString("2001-09-15T09:33:01.001UTC+02:57") << QString("yyyy-MM-ddThh:mm:ss.zt") - << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), Qt::OffsetFromUTC, 10620); + << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), + QTimeZone::fromSecondsAheadOfUtc(10620)); QTest::newRow("offset-from-utc:-03:00") // RFC 3339 offset format << QString("2001-09-15T09:33:01.001-03:00") << QString("yyyy-MM-ddThh:mm:ss.zt") - << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), Qt::OffsetFromUTC, -10800); + << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), + QTimeZone::fromSecondsAheadOfUtc(-10800)); QTest::newRow("offset-from-utc:+0205") // ISO 8601 basic offset format << QString("2001-09-15T09:33:01.001+0205") << QString("yyyy-MM-ddThh:mm:ss.zt") - << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), Qt::OffsetFromUTC, 7500); + << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), + QTimeZone::fromSecondsAheadOfUtc(7500)); QTest::newRow("offset-from-utc:-0401") // ISO 8601 basic offset format << QString("2001-09-15T09:33:01.001-0401") << QString("yyyy-MM-ddThh:mm:ss.zt") - << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), Qt::OffsetFromUTC, -14460); + << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), + QTimeZone::fromSecondsAheadOfUtc(-14460)); QTest::newRow("offset-from-utc:+10") // ISO 8601 basic (hour-only) offset format << QString("2001-09-15T09:33:01.001 +10") << QString("yyyy-MM-ddThh:mm:ss.z t") - << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), Qt::OffsetFromUTC, 36000); + << QDateTime(QDate(2001, 9, 15), QTime(9, 33, 1, 1), + QTimeZone::fromSecondsAheadOfUtc(36000)); QTest::newRow("offset-from-utc:UTC+10:00") // Time-spec specifier at the beginning << QString("UTC+10:00 2008-10-13T07:33") << QString("t yyyy-MM-ddThh:mm") - << QDateTime(QDate(2008, 10, 13), QTime(7, 33), Qt::OffsetFromUTC, 36000); + << QDateTime(QDate(2008, 10, 13), QTime(7, 33), QTimeZone::fromSecondsAheadOfUtc(36000)); QTest::newRow("offset-from-utc:UTC-03:30") // Time-spec specifier in the middle << QString("2008-10-13 UTC-03:30 11.50") << QString("yyyy-MM-dd t hh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, -12600); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), + QTimeZone::fromSecondsAheadOfUtc(-12600)); QTest::newRow("offset-from-utc:UTC-2") // Time-spec specifier joined with text/time << QString("2008-10-13 UTC-2Z11.50") << QString("yyyy-MM-dd tZhh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, -7200); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), QTimeZone::fromSecondsAheadOfUtc(-7200)); QTest::newRow("offset-from-utc:followed-by-colon") << QString("2008-10-13 UTC-0100:11.50") << QString("yyyy-MM-dd t:hh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, -3600); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), QTimeZone::fromSecondsAheadOfUtc(-3600)); QTest::newRow("offset-from-utc:late-colon") << QString("2008-10-13 UTC+05T:11.50") << QString("yyyy-MM-dd tT:hh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, 18000); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), QTimeZone::fromSecondsAheadOfUtc(18000)); QTest::newRow("offset-from-utc:merged-with-time") << QString("2008-10-13 UTC+010011.50") << QString("yyyy-MM-dd thh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, 3600); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), QTimeZone::fromSecondsAheadOfUtc(3600)); QTest::newRow("offset-from-utc:double-colon-delimiter") << QString("2008-10-13 UTC+12::11.50") << QString("yyyy-MM-dd t::hh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, 43200); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), QTimeZone::fromSecondsAheadOfUtc(43200)); QTest::newRow("offset-from-utc:3-digit-with-colon") << QString("2008-10-13 -4:30 11.50") << QString("yyyy-MM-dd t hh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, -16200); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), QTimeZone::fromSecondsAheadOfUtc(-16200)); QTest::newRow("offset-from-utc:merged-with-time") << QString("2008-10-13 UTC+010011.50") << QString("yyyy-MM-dd thh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, 3600); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), QTimeZone::fromSecondsAheadOfUtc(3600)); QTest::newRow("offset-from-utc:with-colon-merged-with-time") << QString("2008-10-13 UTC+01:0011.50") << QString("yyyy-MM-dd thh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, 3600); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), QTimeZone::fromSecondsAheadOfUtc(3600)); QTest::newRow("invalid-offset-from-utc:out-of-range") << QString("2001-09-15T09:33:01.001-50") << QString("yyyy-MM-ddThh:mm:ss.zt") << QDateTime(); @@ -3050,7 +3069,7 @@ void tst_QDateTime::fromStringStringFormat_data() // test unicode QTest::newRow("unicode handling") << QString(u8"2005🤣06🤣28T07🤣57🤣30.001Z") << QString(u8"yyyy🤣MM🤣ddThh🤣mm🤣ss.zt") - << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), Qt::UTC); + << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), UTC); // Two tests derived from malformed ASN.1 strings (QTBUG-84349): QTest::newRow("ASN.1:UTC") @@ -3064,12 +3083,13 @@ void tst_QDateTime::fromStringStringFormat_data() << QDateTime(); // Rich time-zone specifiers (QTBUG-95966): + const auto east3hours = QTimeZone::fromSecondsAheadOfUtc(10800); QTest::newRow("timezone-tt-with-offset:+0300") << QString("2008-10-13 +0300 11.50") << QString("yyyy-MM-dd tt hh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, 10800); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), east3hours); QTest::newRow("timezone-ttt-with-offset:+03:00") << QString("2008-10-13 +03:00 11.50") << QString("yyyy-MM-dd ttt hh.mm") - << QDateTime(QDate(2008, 10, 13), QTime(11, 50), Qt::OffsetFromUTC, 10800); + << QDateTime(QDate(2008, 10, 13), QTime(11, 50), east3hours); QTest::newRow("timezone-tttt-with-offset:+03:00") << QString("2008-10-13 +03:00 11.50") << QString("yyyy-MM-dd tttt hh.mm") << QDateTime(); // Offset not valid when zone name expected. @@ -3086,12 +3106,7 @@ void tst_QDateTime::fromStringStringFormat() QCOMPARE(dt, expected); if (expected.isValid()) { QCOMPARE(dt.timeSpec(), expected.timeSpec()); -#if QT_CONFIG(timezone) - if (expected.timeSpec() == Qt::TimeZone) - QCOMPARE(dt.timeZone(), expected.timeZone()); -#endif - // OffsetFromUTC needs an offset check - we may as well do it for all: - QCOMPARE(dt.offsetFromUtc(), expected.offsetFromUtc()); + QCOMPARE(dt.timeRepresentation(), dt.timeRepresentation()); } else { QCOMPARE(dt.isValid(), expected.isValid()); QCOMPARE(dt.toMSecsSinceEpoch(), expected.toMSecsSinceEpoch()); @@ -3158,7 +3173,7 @@ void tst_QDateTime::fromStringStringFormat_localTimeZone_data() QTest::newRow("Helsinki-joins-EET") << QByteArrayLiteral("Europe/Helsinki") << QString("210506000000Z") << QString("yyMMddHHmmsst") - << QDateTime(QDate(1921, 5, 6), QTime(0, 0), Qt::UTC); + << QDateTime(QDate(1921, 5, 6), QTime(0, 0), UTC); } if (lacksRows) QSKIP("Testcases all use zones unsupported on this platform"); @@ -3182,16 +3197,17 @@ void tst_QDateTime::offsetFromUtc() QCOMPARE(QDateTime().offsetFromUtc(), 0); // Offset constructor - QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0), Qt::OffsetFromUTC, 60 * 60); + QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0), QTimeZone::fromSecondsAheadOfUtc(60 * 60)); QCOMPARE(dt1.offsetFromUtc(), 60 * 60); + QVERIFY(dt1.timeRepresentation().isValid()); #if QT_CONFIG(timezone) QVERIFY(dt1.timeZone().isValid()); #endif - dt1 = QDateTime(QDate(2013, 1, 1), QTime(1, 0), Qt::OffsetFromUTC, -60 * 60); + dt1 = QDateTime(QDate(2013, 1, 1), QTime(1, 0), QTimeZone::fromSecondsAheadOfUtc(-60 * 60)); QCOMPARE(dt1.offsetFromUtc(), -60 * 60); // UTC should be 0 offset - QDateTime dt2(QDate(2013, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime dt2(QDate(2013, 1, 1), QTime(0, 0), UTC); QCOMPARE(dt2.offsetFromUtc(), 0); // LocalTime should vary @@ -3291,7 +3307,7 @@ void tst_QDateTime::setOffsetFromUtc() void tst_QDateTime::toOffsetFromUtc() { - QDateTime dt1(QDate(2013, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime dt1(QDate(2013, 1, 1), QTime(0, 0), QTimeZone::UTC); QDateTime dt2 = dt1.toOffsetFromUtc(60 * 60); QCOMPARE(dt2, dt1); @@ -3386,12 +3402,12 @@ void tst_QDateTime::zoneAtTime() void tst_QDateTime::timeZoneAbbreviation() { - QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0), Qt::OffsetFromUTC, 60 * 60); + QDateTime dt1(QDate(2013, 1, 1), QTime(1, 0), QTimeZone::fromSecondsAheadOfUtc(60 * 60)); QCOMPARE(dt1.timeZoneAbbreviation(), QString("UTC+01:00")); - QDateTime dt2(QDate(2013, 1, 1), QTime(1, 0), Qt::OffsetFromUTC, -60 * 60); + QDateTime dt2(QDate(2013, 1, 1), QTime(1, 0), QTimeZone::fromSecondsAheadOfUtc(-60 * 60)); QCOMPARE(dt2.timeZoneAbbreviation(), QString("UTC-01:00")); - QDateTime dt3(QDate(2013, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime dt3(QDate(2013, 1, 1), QTime(0, 0), UTC); QCOMPARE(dt3.timeZoneAbbreviation(), QString("UTC")); // LocalTime should vary @@ -3500,8 +3516,8 @@ void tst_QDateTime::utcOffsetLessThan() const QDateTime dt1(QDate(2002, 10, 10), QTime(0, 0)); QDateTime dt2(dt1); - dt1.setOffsetFromUtc(-(2 * 60 * 60)); // Minus two hours. - dt2.setOffsetFromUtc(-(3 * 60 * 60)); // Minus three hours. + dt1.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-(2 * 60 * 60))); // Minus two hours. + dt2.setTimeZone(QTimeZone::fromSecondsAheadOfUtc(-(3 * 60 * 60))); // Minus three hours. QVERIFY(dt1 != dt2); QVERIFY(!(dt1 == dt2)); @@ -3511,14 +3527,14 @@ void tst_QDateTime::utcOffsetLessThan() const void tst_QDateTime::isDaylightTime() const { - QDateTime utc1(QDate(2012, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime utc1(QDate(2012, 1, 1), QTime(0, 0), UTC); QVERIFY(!utc1.isDaylightTime()); - QDateTime utc2(QDate(2012, 6, 1), QTime(0, 0), Qt::UTC); + QDateTime utc2(QDate(2012, 6, 1), QTime(0, 0), UTC); QVERIFY(!utc2.isDaylightTime()); - QDateTime offset1(QDate(2012, 1, 1), QTime(0, 0), Qt::OffsetFromUTC, 1 * 60 * 60); + QDateTime offset1(QDate(2012, 1, 1), QTime(0, 0), QTimeZone::fromSecondsAheadOfUtc(60 * 60)); QVERIFY(!offset1.isDaylightTime()); - QDateTime offset2(QDate(2012, 6, 1), QTime(0, 0), Qt::OffsetFromUTC, 1 * 60 * 60); + QDateTime offset2(QDate(2012, 6, 1), QTime(0, 0), QTimeZone::fromSecondsAheadOfUtc(60 * 60)); QVERIFY(!offset2.isDaylightTime()); if (zoneIsCET) { @@ -3547,8 +3563,8 @@ void tst_QDateTime::daylightTransitions() const const qint64 spring2012 = 1332637200000; const qint64 autumn2012 = 1351386000000; const qint64 msecsOneHour = 3600000; - QCOMPARE(spring2012, QDateTime(QDate(2012, 3, 25), QTime(1, 0), Qt::UTC).toMSecsSinceEpoch()); - QCOMPARE(autumn2012, QDateTime(QDate(2012, 10, 28), QTime(1, 0), Qt::UTC).toMSecsSinceEpoch()); + QCOMPARE(spring2012, QDateTime(QDate(2012, 3, 25), QTime(1, 0), UTC).toMSecsSinceEpoch()); + QCOMPARE(autumn2012, QDateTime(QDate(2012, 10, 28), QTime(1, 0), UTC).toMSecsSinceEpoch()); // Test for correct behviour for StandardTime -> DaylightTime transition, i.e. missing hour @@ -3590,16 +3606,15 @@ void tst_QDateTime::daylightTransitions() const QCOMPARE(after.toMSecsSinceEpoch(), spring2012); // Test changing time spec re-validates the date/time - - QDateTime utc(QDate(2012, 3, 25), QTime(2, 0), Qt::UTC); + QDateTime utc(QDate(2012, 3, 25), QTime(2, 0), UTC); QVERIFY(utc.isValid()); QCOMPARE(utc.date(), QDate(2012, 3, 25)); QCOMPARE(utc.time(), QTime(2, 0)); - utc.setTimeSpec(Qt::LocalTime); + utc.setTimeZone(QTimeZone::LocalTime); QVERIFY(!utc.isValid()); QCOMPARE(utc.date(), QDate(2012, 3, 25)); QCOMPARE(utc.time(), QTime(2, 0)); - utc.setTimeSpec(Qt::UTC); + utc.setTimeZone(UTC); QVERIFY(utc.isValid()); QCOMPARE(utc.date(), QDate(2012, 3, 25)); QCOMPARE(utc.time(), QTime(2, 0)); @@ -3942,7 +3957,7 @@ void tst_QDateTime::timeZones() const QTimeZone nzTzOffset = QTimeZone(12 * 3600); // During Standard Time NZ is +12:00 - QDateTime utcStd(QDate(2012, 6, 1), QTime(0, 0), Qt::UTC); + QDateTime utcStd(QDate(2012, 6, 1), QTime(0, 0), UTC); QDateTime nzStd(QDate(2012, 6, 1), QTime(12, 0), nzTz); QDateTime nzStdOffset(QDate(2012, 6, 1), QTime(12, 0), nzTzOffset); @@ -3967,7 +3982,7 @@ void tst_QDateTime::timeZones() const QCOMPARE(nzStdOffset.toMSecsSinceEpoch(), utcStd.toMSecsSinceEpoch()); // During Daylight Time NZ is +13:00 - QDateTime utcDst(QDate(2012, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime utcDst(QDate(2012, 1, 1), QTime(0, 0), UTC); QDateTime nzDst(QDate(2012, 1, 1), QTime(13, 0), nzTz); QVERIFY(nzDst.isValid()); @@ -3994,7 +4009,7 @@ void tst_QDateTime::timeZones() const QCOMPARE(aus.date(), QDate(2012, 6, 1)); QCOMPARE(aus.time(), QTime(10, 0)); - QDateTime dt1(QDate(2012, 6, 1), QTime(0, 0), Qt::UTC); + QDateTime dt1(QDate(2012, 6, 1), QTime(0, 0), UTC); QCOMPARE(dt1.timeSpec(), Qt::UTC); dt1.setTimeZone(nzTz); QCOMPARE(dt1.timeSpec(), Qt::TimeZone); @@ -4006,13 +4021,13 @@ void tst_QDateTime::timeZones() const QCOMPARE(dt2.date(), dt1.date()); QCOMPARE(dt2.time(), dt1.time()); QCOMPARE(dt2.timeSpec(), dt1.timeSpec()); - QCOMPARE(dt2.timeZone(), dt1.timeZone()); + QCOMPARE(dt2.timeRepresentation(), dt1.timeRepresentation()); QDateTime dt3 = QDateTime::fromMSecsSinceEpoch(1338465600000, nzTz); QCOMPARE(dt3.date(), dt1.date()); QCOMPARE(dt3.time(), dt1.time()); QCOMPARE(dt3.timeSpec(), dt1.timeSpec()); - QCOMPARE(dt3.timeZone(), dt1.timeZone()); + QCOMPARE(dt3.timeRepresentation(), dt1.timeRepresentation()); // The start of year 1 should be *describable* in any zone (QTBUG-78051) dt3 = QDateTime(QDate(1, 1, 1), QTime(0, 0), ausTz); @@ -4042,7 +4057,7 @@ void tst_QDateTime::timeZones() const // Standard Time to Daylight Time 2013 on 2013-03-31 is 2:00 local time / 1:00 UTC const qint64 gapMSecs = 1364691600000; - QCOMPARE(gapMSecs, QDateTime(QDate(2013, 3, 31), QTime(1, 0), Qt::UTC).toMSecsSinceEpoch()); + QCOMPARE(gapMSecs, QDateTime(QDate(2013, 3, 31), QTime(1, 0), UTC).toMSecsSinceEpoch()); // Test MSecs to local // - Test 1 msec before tran = 01:59:59.999 @@ -4080,7 +4095,7 @@ void tst_QDateTime::timeZones() const // Standard Time to Daylight Time 2013 on 2013-10-27 is 3:00 local time / 1:00 UTC const qint64 replayMSecs = 1382835600000; - QCOMPARE(replayMSecs, QDateTime(QDate(2013, 10, 27), QTime(1, 0), Qt::UTC).toMSecsSinceEpoch()); + QCOMPARE(replayMSecs, QDateTime(QDate(2013, 10, 27), QTime(1, 0), UTC).toMSecsSinceEpoch()); // Test MSecs to local // - Test 1 hour before tran = 02:00:00 local first occurrence @@ -4161,7 +4176,7 @@ void tst_QDateTime::systemTimeZoneChange() const #endif const QDateTime localDate = QDateTime(date, early); - const QDateTime utcDate = QDateTime(date, early, Qt::UTC); + const QDateTime utcDate = QDateTime(date, early, UTC); const qint64 localMsecs = localDate.toMSecsSinceEpoch(); const qint64 utcMsecs = utcDate.toMSecsSinceEpoch(); #if QT_CONFIG(timezone) @@ -4187,7 +4202,7 @@ void tst_QDateTime::systemTimeZoneChange() const QCOMPARE(localDate, QDateTime(date, early)); // Note: localDate.toMSecsSinceEpoch == localMsecs, unchanged, iff localDate is pimpled. QVERIFY(localMsecs != QDateTime(date, early).toMSecsSinceEpoch()); - QCOMPARE(utcDate, QDateTime(date, early, Qt::UTC)); + QCOMPARE(utcDate, QDateTime(date, early, UTC)); QCOMPARE(utcDate.toMSecsSinceEpoch(), utcMsecs); #if QT_CONFIG(timezone) QCOMPARE(tzDate.toMSecsSinceEpoch(), tzMsecs); @@ -4207,17 +4222,19 @@ void tst_QDateTime::invalid_data() const QTest::newRow("simple") << invalidDate << Qt::LocalTime << true; QTest::newRow("UTC") << invalidDate.toUTC() << Qt::UTC << true; QTest::newRow("offset") - << invalidDate.toOffsetFromUtc(3600) << Qt::OffsetFromUTC << true; + << invalidDate.toTimeZone(QTimeZone::fromSecondsAheadOfUtc(3600)) << Qt::OffsetFromUTC + << true; #if QT_CONFIG(timezone) QTest::newRow("CET") << invalidDate.toTimeZone(QTimeZone("Europe/Oslo")) << Qt::TimeZone << true; // Crash tests, QTBUG-80146: QTest::newRow("nozone+construct") - << QDateTime(QDate(1970, 1, 1), QTime(12, 0), QTimeZone()) << Qt::TimeZone << false; + << QDateTime(QDate(1970, 1, 1), QTime(12, 0), QTimeZone()) + << Qt::TimeZone << false; QTest::newRow("nozone+fromMSecs") << QDateTime::fromMSecsSinceEpoch(42, QTimeZone()) << Qt::TimeZone << false; - QDateTime valid(QDate(1970, 1, 1), QTime(12, 0), Qt::UTC); + QDateTime valid(QDate(1970, 1, 1), QTime(12, 0), UTC); QTest::newRow("tonozone") << valid.toTimeZone(QTimeZone()) << Qt::TimeZone << false; #endif } @@ -4233,33 +4250,31 @@ void tst_QDateTime::invalid() const if (!goodZone) QCOMPARE(when.toMSecsSinceEpoch(), 0); QVERIFY(!when.isDaylightTime()); -#if QT_CONFIG(timezone) - QCOMPARE(when.timeZone().isValid(), goodZone); -#endif + QCOMPARE(when.timeRepresentation().isValid(), goodZone); } void tst_QDateTime::range() const { using Bounds = std::numeric_limits; - QCOMPARE(QDateTime::fromMSecsSinceEpoch(Bounds::min() + 1, Qt::UTC).date().year(), + QCOMPARE(QDateTime::fromMSecsSinceEpoch(Bounds::min() + 1, UTC).date().year(), int(QDateTime::YearRange::First)); - QCOMPARE(QDateTime::fromMSecsSinceEpoch(Bounds::max() - 1, Qt::UTC).date().year(), + QCOMPARE(QDateTime::fromMSecsSinceEpoch(Bounds::max() - 1, UTC).date().year(), int(QDateTime::YearRange::Last)); constexpr qint64 millisPerDay = 24 * 3600 * 1000; constexpr qint64 wholeDays = Bounds::max() / millisPerDay; constexpr qint64 millisRemainder = Bounds::max() % millisPerDay; QVERIFY(QDateTime(QDate(1970, 1, 1).addDays(wholeDays), QTime::fromMSecsSinceStartOfDay(millisRemainder), - Qt::UTC).isValid()); + UTC).isValid()); QVERIFY(!QDateTime(QDate(1970, 1, 1).addDays(wholeDays), QTime::fromMSecsSinceStartOfDay(millisRemainder + 1), - Qt::UTC).isValid()); + UTC).isValid()); QVERIFY(QDateTime(QDate(1970, 1, 1).addDays(-wholeDays - 1), QTime::fromMSecsSinceStartOfDay(3600 * 24000 - millisRemainder - 1), - Qt::UTC).isValid()); + UTC).isValid()); QVERIFY(!QDateTime(QDate(1970, 1, 1).addDays(-wholeDays - 1), QTime::fromMSecsSinceStartOfDay(3600 * 24000 - millisRemainder - 2), - Qt::UTC).isValid()); + UTC).isValid()); } void tst_QDateTime::macTypes() @@ -4287,22 +4302,22 @@ void tst_QDateTime::stdCompatibilitySysTime_data() QTest::newRow("zero") << StdSysMillis(0s) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0), Qt::UTC); + << QDateTime(QDate(1970, 1, 1), QTime(0, 0), UTC); QTest::newRow("1s") << StdSysMillis(1s) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), Qt::UTC); + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), UTC); QTest::newRow("1ms") << StdSysMillis(1ms) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0, 1), Qt::UTC); + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0, 1), UTC); QTest::newRow("365d") << StdSysMillis(days(365)) - << QDateTime(QDate(1971, 1, 1), QTime(0, 0, 0), Qt::UTC); + << QDateTime(QDate(1971, 1, 1), QTime(0, 0), UTC); QTest::newRow("-1s") << StdSysMillis(-1s) - << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), Qt::UTC); + << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), UTC); QTest::newRow("-1ms") << StdSysMillis(-1ms) - << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59, 999), Qt::UTC); + << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59, 999), UTC); { // The first leap second occurred on 30 June 1972 at 23:59:60. @@ -4311,7 +4326,7 @@ void tst_QDateTime::stdCompatibilitySysTime_data() const sys_days firstLeapSecondDateAsSysDays = firstLeapSecondDate; QTest::newRow("first_leap_second") << StdSysMillis(firstLeapSecondDateAsSysDays) - << QDateTime(QDate(1972, 7, 1), QTime(0, 0, 0), Qt::UTC); + << QDateTime(QDate(1972, 7, 1), QTime(0, 0), UTC); } { @@ -4320,7 +4335,7 @@ void tst_QDateTime::stdCompatibilitySysTime_data() const StdSysMillis dateTime = date + 3h + 10min + 42s; QTest::newRow("2000-01-31 03:10:42") << dateTime - << QDateTime(QDate(2000, 1, 31), QTime(3, 10, 42), Qt::UTC); + << QDateTime(QDate(2000, 1, 31), QTime(3, 10, 42), UTC); } #else QSKIP("This test requires C++20's ."); diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp index 4c73bb7c9f1..b63e506ad2c 100644 --- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp @@ -4,6 +4,7 @@ #include #include #include + #include #if defined(Q_OS_WIN) @@ -73,8 +74,8 @@ private Q_SLOTS: void tst_QTimeZone::printTimeZone(const QTimeZone &tz) { QDateTime now = QDateTime::currentDateTime(); - QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC); - QDateTime jun = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC); + QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0), QTimeZone::UTC); + QDateTime jun = QDateTime(QDate(2012, 6, 1), QTime(0, 0), QTimeZone::UTC); qDebug() << ""; qDebug() << "Time Zone = " << tz; qDebug() << ""; @@ -158,9 +159,9 @@ void tst_QTimeZone::createTest() QCOMPARE(tz.territory(), QLocale::NewZealand); - QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC); - QDateTime jun = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC); - QDateTime janPrev = QDateTime(QDate(2011, 1, 1), QTime(0, 0, 0), Qt::UTC); + QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0), QTimeZone::UTC); + QDateTime jun = QDateTime(QDate(2012, 6, 1), QTime(0, 0), QTimeZone::UTC); + QDateTime janPrev = QDateTime(QDate(2011, 1, 1), QTime(0, 0), QTimeZone::UTC); QCOMPARE(tz.offsetFromUtc(jan), 13 * 3600); QCOMPARE(tz.offsetFromUtc(jun), 12 * 3600); @@ -180,7 +181,8 @@ void tst_QTimeZone::createTest() QTimeZone::OffsetData tran = tz.nextTransition(jan); // 2012-04-01 03:00 NZDT, +13 -> +12 QCOMPARE(tran.atUtc, - QDateTime(QDate(2012, 4, 1), QTime(3, 0), Qt::OffsetFromUTC, 13 * 3600)); + QDateTime(QDate(2012, 4, 1), QTime(3, 0), + QTimeZone::fromSecondsAheadOfUtc(13 * 3600))); QCOMPARE(tran.offsetFromUtc, 12 * 3600); QCOMPARE(tran.standardTimeOffset, 12 * 3600); QCOMPARE(tran.daylightTimeOffset, 0); @@ -188,7 +190,8 @@ void tst_QTimeZone::createTest() tran = tz.nextTransition(jun); // 2012-09-30 02:00 NZST, +12 -> +13 QCOMPARE(tran.atUtc, - QDateTime(QDate(2012, 9, 30), QTime(2, 0), Qt::OffsetFromUTC, 12 * 3600)); + QDateTime(QDate(2012, 9, 30), QTime(2, 0), + QTimeZone::fromSecondsAheadOfUtc(12 * 3600))); QCOMPARE(tran.offsetFromUtc, 13 * 3600); QCOMPARE(tran.standardTimeOffset, 12 * 3600); QCOMPARE(tran.daylightTimeOffset, 3600); @@ -196,7 +199,8 @@ void tst_QTimeZone::createTest() tran = tz.previousTransition(jan); // 2011-09-25 02:00 NZST, +12 -> +13 QCOMPARE(tran.atUtc, - QDateTime(QDate(2011, 9, 25), QTime(2, 0), Qt::OffsetFromUTC, 12 * 3600)); + QDateTime(QDate(2011, 9, 25), QTime(2, 0), + QTimeZone::fromSecondsAheadOfUtc(12 * 3600))); QCOMPARE(tran.offsetFromUtc, 13 * 3600); QCOMPARE(tran.standardTimeOffset, 12 * 3600); QCOMPARE(tran.daylightTimeOffset, 3600); @@ -204,17 +208,20 @@ void tst_QTimeZone::createTest() tran = tz.previousTransition(jun); // 2012-04-01 03:00 NZDT, +13 -> +12 (again) QCOMPARE(tran.atUtc, - QDateTime(QDate(2012, 4, 1), QTime(3, 0), Qt::OffsetFromUTC, 13 * 3600)); + QDateTime(QDate(2012, 4, 1), QTime(3, 0), + QTimeZone::fromSecondsAheadOfUtc(13 * 3600))); QCOMPARE(tran.offsetFromUtc, 12 * 3600); QCOMPARE(tran.standardTimeOffset, 12 * 3600); QCOMPARE(tran.daylightTimeOffset, 0); QTimeZone::OffsetDataList expected; // Reuse 2012's fall-back data for 2011-04-03: - tran.atUtc = QDateTime(QDate(2011, 4, 3), QTime(3, 0), Qt::OffsetFromUTC, 13 * 3600); + tran.atUtc = QDateTime(QDate(2011, 4, 3), QTime(3, 0), + QTimeZone::fromSecondsAheadOfUtc(13 * 3600)); expected << tran; // 2011's spring-forward: - tran.atUtc = QDateTime(QDate(2011, 9, 25), QTime(2, 0), Qt::OffsetFromUTC, 12 * 3600); + tran.atUtc = QDateTime(QDate(2011, 9, 25), QTime(2, 0), + QTimeZone::fromSecondsAheadOfUtc(12 * 3600)); tran.offsetFromUtc = 13 * 3600; tran.daylightTimeOffset = 3600; expected << tran; @@ -256,9 +263,9 @@ void tst_QTimeZone::nullTest() QCOMPARE(nullTz1.territory(), QLocale::AnyTerritory); QCOMPARE(nullTz1.comment(), QString()); - QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC); - QDateTime jun = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC); - QDateTime janPrev = QDateTime(QDate(2011, 1, 1), QTime(0, 0, 0), Qt::UTC); + QDateTime jan = QDateTime(QDate(2012, 1, 1), QTime(0, 0), QTimeZone::UTC); + QDateTime jun = QDateTime(QDate(2012, 6, 1), QTime(0, 0), QTimeZone::UTC); + QDateTime janPrev = QDateTime(QDate(2011, 1, 1), QTime(0, 0), QTimeZone::UTC); QCOMPARE(nullTz1.abbreviation(jan), QString()); QCOMPARE(nullTz1.displayName(jan), QString()); @@ -514,7 +521,7 @@ void tst_QTimeZone::systemZone() QDate(2038, 1, 20) // First day after 32-bit time_t's range }; for (const auto &date : dates) - QCOMPARE(date.startOfDay(Qt::LocalTime), date.startOfDay(zone)); + QCOMPARE(date.startOfDay(QTimeZone::LocalTime), date.startOfDay(zone)); #if __cpp_lib_chrono >= 201907L const std::chrono::time_zone *currentTimeZone = std::chrono::current_zone(); @@ -636,7 +643,7 @@ void tst_QTimeZone::utcOffsetId() QTimeZone zone(id); QCOMPARE(zone.isValid(), valid); if (valid) { - QDateTime epoch(QDate(1970, 1, 1), QTime(0, 0, 0), Qt::UTC); + QDateTime epoch(QDate(1970, 1, 1), QTime(0, 0), QTimeZone::UTC); QFETCH(int, offset); QCOMPARE(zone.offsetFromUtc(epoch), offset); QVERIFY(!zone.hasDaylightTime()); @@ -669,15 +676,15 @@ void tst_QTimeZone::specificTransition_data() QTest::newRow("Moscow/2014") // From original bug-report << QByteArray("Europe/Moscow") << QDate(2011, 4, 1) << QDate(2021, 12, 31) << 1 - << QDateTime(QDate(2014, 10, 26), QTime(2, 0, 0), - Qt::OffsetFromUTC, 4 * 3600).toUTC() + << QDateTime(QDate(2014, 10, 26), QTime(2, 0), + QTimeZone::fromSecondsAheadOfUtc(4 * 3600)).toUTC() << 3 * 3600 << 3 * 3600 << 0; } QTest::newRow("Moscow/2011") // Transition on 2011-03-27 << QByteArray("Europe/Moscow") << QDate(2010, 11, 1) << QDate(2014, 10, 25) << 1 - << QDateTime(QDate(2011, 3, 27), QTime(2, 0, 0), - Qt::OffsetFromUTC, 3 * 3600).toUTC() + << QDateTime(QDate(2011, 3, 27), QTime(2, 0), + QTimeZone::fromSecondsAheadOfUtc(3 * 3600)).toUTC() << 4 * 3600 << 4 * 3600 << 0; } @@ -849,12 +856,13 @@ void tst_QTimeZone::availableTimeZoneIds() void tst_QTimeZone::stressTest() { + const auto UTC = QTimeZone::UTC; const QList idList = QTimeZone::availableTimeZoneIds(); for (const QByteArray &id : idList) { QTimeZone testZone = QTimeZone(id); QCOMPARE(testZone.isValid(), true); QCOMPARE(testZone.id(), id); - QDateTime testDate = QDateTime(QDate(2015, 1, 1), QTime(0, 0, 0), Qt::UTC); + QDateTime testDate = QDateTime(QDate(2015, 1, 1), QTime(0, 0), UTC); testZone.territory(); testZone.comment(); testZone.displayName(testDate); @@ -871,10 +879,10 @@ void tst_QTimeZone::stressTest() testZone.nextTransition(testDate); testZone.previousTransition(testDate); // Dates known to be outside possible tz file pre-calculated rules range - QDateTime lowDate1 = QDateTime(QDate(1800, 1, 1), QTime(0, 0, 0), Qt::UTC); - QDateTime lowDate2 = QDateTime(QDate(1800, 6, 1), QTime(0, 0, 0), Qt::UTC); - QDateTime highDate1 = QDateTime(QDate(2200, 1, 1), QTime(0, 0, 0), Qt::UTC); - QDateTime highDate2 = QDateTime(QDate(2200, 6, 1), QTime(0, 0, 0), Qt::UTC); + QDateTime lowDate1 = QDateTime(QDate(1800, 1, 1), QTime(0, 0), UTC); + QDateTime lowDate2 = QDateTime(QDate(1800, 6, 1), QTime(0, 0), UTC); + QDateTime highDate1 = QDateTime(QDate(2200, 1, 1), QTime(0, 0), UTC); + QDateTime highDate2 = QDateTime(QDate(2200, 6, 1), QTime(0, 0), UTC); testZone.nextTransition(lowDate1); testZone.nextTransition(lowDate2); testZone.previousTransition(lowDate2); @@ -1196,8 +1204,8 @@ void tst_QTimeZone::icuTest() { #if defined(QT_BUILD_INTERNAL) && QT_CONFIG(icu) // Known datetimes - qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); - qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); + qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0), QTimeZone::UTC).toMSecsSinceEpoch(); + qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0), QTimeZone::UTC).toMSecsSinceEpoch(); // Test default constructor QIcuTimeZonePrivate tzpd; @@ -1241,9 +1249,10 @@ void tst_QTimeZone::icuTest() void tst_QTimeZone::tzTest() { #if defined QT_BUILD_INTERNAL && defined Q_OS_UNIX && !defined Q_OS_DARWIN && !defined Q_OS_ANDROID + const auto UTC = QTimeZone::UTC; // Known datetimes - qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); - qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); + qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0), UTC).toMSecsSinceEpoch(); + qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0), UTC).toMSecsSinceEpoch(); // Test default constructor QTzTimeZonePrivate tzpd; @@ -1276,8 +1285,8 @@ void tst_QTimeZone::tzTest() // It shouldn't have any transitions. QTimeZone::hasTransitions() only says // whether the backend supports them, so ask for transitions in a wide // enough interval that one would show up, if there are any: - QVERIFY(permaDst.transitions(QDate(2015, 1, 1).startOfDay(Qt::UTC).toMSecsSinceEpoch(), - QDate(2020, 1, 1).startOfDay(Qt::UTC).toMSecsSinceEpoch() + QVERIFY(permaDst.transitions(QDate(2015, 1, 1).startOfDay(UTC).toMSecsSinceEpoch(), + QDate(2020, 1, 1).startOfDay(UTC).toMSecsSinceEpoch() ).isEmpty()); QTimeZone tzBrazil("BRT+3"); // parts of Northern Brazil, as a POSIX rule @@ -1348,14 +1357,16 @@ void tst_QTimeZone::tzTest() } dat = tzp.nextTransition(ancient); - QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, Qt::OffsetFromUTC, 3600), - QDateTime(QDate(1893, 4, 1), QTime(0, 6, 32), Qt::OffsetFromUTC, 3600)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, + QTimeZone::fromSecondsAheadOfUtc(3600)), + QDateTime(QDate(1893, 4, 1), QTime(0, 6, 32), + QTimeZone::fromSecondsAheadOfUtc(3600))); QCOMPARE(dat.standardTimeOffset, 3600); QCOMPARE(dat.daylightTimeOffset, 0); // Date-times late enough to exercise POSIX rules: - qint64 stdHi = QDate(2100, 1, 1).startOfDay(Qt::UTC).toMSecsSinceEpoch(); - qint64 dstHi = QDate(2100, 6, 1).startOfDay(Qt::UTC).toMSecsSinceEpoch(); + qint64 stdHi = QDate(2100, 1, 1).startOfDay(UTC).toMSecsSinceEpoch(); + qint64 dstHi = QDate(2100, 6, 1).startOfDay(UTC).toMSecsSinceEpoch(); // Relevant last Sundays in October and March: QCOMPARE(Qt::DayOfWeek(QDate(2099, 10, 25).dayOfWeek()), Qt::Sunday); QCOMPARE(Qt::DayOfWeek(QDate(2100, 3, 28).dayOfWeek()), Qt::Sunday); @@ -1375,32 +1386,33 @@ void tst_QTimeZone::tzTest() dat = tzp.previousTransition(stdHi); QCOMPARE(dat.abbreviation, QStringLiteral("CET")); - QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, Qt::UTC), - QDateTime(QDate(2099, 10, 25), QTime(3, 0), Qt::OffsetFromUTC, 7200)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, UTC), + QDateTime(QDate(2099, 10, 25), QTime(3, 0), QTimeZone::fromSecondsAheadOfUtc(7200))); QCOMPARE(dat.offsetFromUtc, 3600); QCOMPARE(dat.standardTimeOffset, 3600); QCOMPARE(dat.daylightTimeOffset, 0); dat = tzp.previousTransition(dstHi); QCOMPARE(dat.abbreviation, QStringLiteral("CEST")); - QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, Qt::UTC), - QDateTime(QDate(2100, 3, 28), QTime(2, 0), Qt::OffsetFromUTC, 3600)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, UTC), + QDateTime(QDate(2100, 3, 28), QTime(2, 0), QTimeZone::fromSecondsAheadOfUtc(3600))); QCOMPARE(dat.offsetFromUtc, 7200); QCOMPARE(dat.standardTimeOffset, 3600); QCOMPARE(dat.daylightTimeOffset, 3600); dat = tzp.nextTransition(stdHi); QCOMPARE(dat.abbreviation, QStringLiteral("CEST")); - QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, Qt::UTC), - QDateTime(QDate(2100, 3, 28), QTime(2, 0), Qt::OffsetFromUTC, 3600)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, UTC), + QDateTime(QDate(2100, 3, 28), QTime(2, 0), QTimeZone::fromSecondsAheadOfUtc(3600))); QCOMPARE(dat.offsetFromUtc, 7200); QCOMPARE(dat.standardTimeOffset, 3600); QCOMPARE(dat.daylightTimeOffset, 3600); dat = tzp.nextTransition(dstHi); QCOMPARE(dat.abbreviation, QStringLiteral("CET")); - QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, Qt::OffsetFromUTC, 3600), - QDateTime(QDate(2100, 10, 31), QTime(3, 0), Qt::OffsetFromUTC, 7200)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(dat.atMSecsSinceEpoch, + QTimeZone::fromSecondsAheadOfUtc(3600)), + QDateTime(QDate(2100, 10, 31), QTime(3, 0), QTimeZone::fromSecondsAheadOfUtc(7200))); QCOMPARE(dat.offsetFromUtc, 3600); QCOMPARE(dat.standardTimeOffset, 3600); QCOMPARE(dat.daylightTimeOffset, 0); @@ -1429,7 +1441,7 @@ void tst_QTimeZone::tzTest() QCOMPARE(tzBarnaul.data(std).abbreviation, QString("+07")); // first full day of the new rule (tzdata2016b) - QDateTime dt(QDate(2016, 3, 28), QTime(0, 0, 0), Qt::UTC); + QDateTime dt(QDate(2016, 3, 28), QTime(0, 0), UTC); QCOMPARE(tzBarnaul.data(dt.toMSecsSinceEpoch()).abbreviation, QString("+07")); } #endif // QT_BUILD_INTERNAL && Q_OS_UNIX && !Q_OS_DARWIN @@ -1439,8 +1451,8 @@ void tst_QTimeZone::macTest() { #if defined(QT_BUILD_INTERNAL) && defined(Q_OS_DARWIN) // Known datetimes - qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); - qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); + qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0), QTimeZone::UTC).toMSecsSinceEpoch(); + qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0), QTimeZone::UTC).toMSecsSinceEpoch(); // Test default constructor QMacTimeZonePrivate tzpd; @@ -1495,8 +1507,8 @@ void tst_QTimeZone::winTest() { #if defined(QT_BUILD_INTERNAL) && defined(USING_WIN_TZ) // Known datetimes - qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); - qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); + qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0), QTimeZone::UTC).toMSecsSinceEpoch(); + qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0), QTimeZone::UTC).toMSecsSinceEpoch(); // Test default constructor QWinTimeZonePrivate tzpd; @@ -1598,9 +1610,11 @@ void tst_QTimeZone::localeSpecificDisplayName() void tst_QTimeZone::testCetPrivate(const QTimeZonePrivate &tzp) { // Known datetimes - qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); - qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); - qint64 prev = QDateTime(QDate(2011, 1, 1), QTime(0, 0, 0), Qt::UTC).toMSecsSinceEpoch(); + const auto UTC = QTimeZone::UTC; + const auto eastOneHour = QTimeZone::fromSecondsAheadOfUtc(3600); + qint64 std = QDateTime(QDate(2012, 1, 1), QTime(0, 0), UTC).toMSecsSinceEpoch(); + qint64 dst = QDateTime(QDate(2012, 6, 1), QTime(0, 0), UTC).toMSecsSinceEpoch(); + qint64 prev = QDateTime(QDate(2011, 1, 1), QTime(0, 0), UTC).toMSecsSinceEpoch(); QCOMPARE(tzp.offsetFromUtc(std), 3600); QCOMPARE(tzp.offsetFromUtc(dst), 7200); @@ -1633,32 +1647,34 @@ void tst_QTimeZone::testCetPrivate(const QTimeZonePrivate &tzp) if (tzp.hasTransitions()) { QTimeZonePrivate::Data tran = tzp.nextTransition(std); // 2012-03-25 02:00 CET, +1 -> +2 - QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, Qt::UTC), - QDateTime(QDate(2012, 3, 25), QTime(2, 0), Qt::OffsetFromUTC, 3600)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, UTC), + QDateTime(QDate(2012, 3, 25), QTime(2, 0), eastOneHour)); QCOMPARE(tran.offsetFromUtc, 7200); QCOMPARE(tran.standardTimeOffset, 3600); QCOMPARE(tran.daylightTimeOffset, 3600); tran = tzp.nextTransition(dst); // 2012-10-28 03:00 CEST, +2 -> +1 - QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, Qt::UTC), - QDateTime(QDate(2012, 10, 28), QTime(3, 0), Qt::OffsetFromUTC, 2 * 3600)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, UTC), + QDateTime(QDate(2012, 10, 28), QTime(3, 0), + QTimeZone::fromSecondsAheadOfUtc(2 * 3600))); QCOMPARE(tran.offsetFromUtc, 3600); QCOMPARE(tran.standardTimeOffset, 3600); QCOMPARE(tran.daylightTimeOffset, 0); tran = tzp.previousTransition(std); // 2011-10-30 03:00 CEST, +2 -> +1 - QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, Qt::UTC), - QDateTime(QDate(2011, 10, 30), QTime(3, 0), Qt::OffsetFromUTC, 2 * 3600)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, UTC), + QDateTime(QDate(2011, 10, 30), QTime(3, 0), + QTimeZone::fromSecondsAheadOfUtc(2 * 3600))); QCOMPARE(tran.offsetFromUtc, 3600); QCOMPARE(tran.standardTimeOffset, 3600); QCOMPARE(tran.daylightTimeOffset, 0); tran = tzp.previousTransition(dst); // 2012-03-25 02:00 CET, +1 -> +2 (again) - QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, Qt::UTC), - QDateTime(QDate(2012, 3, 25), QTime(2, 0), Qt::OffsetFromUTC, 3600)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, UTC), + QDateTime(QDate(2012, 3, 25), QTime(2, 0), eastOneHour)); QCOMPARE(tran.offsetFromUtc, 7200); QCOMPARE(tran.standardTimeOffset, 3600); QCOMPARE(tran.daylightTimeOffset, 3600); @@ -1666,14 +1682,15 @@ void tst_QTimeZone::testCetPrivate(const QTimeZonePrivate &tzp) QTimeZonePrivate::DataList expected; // 2011-03-27 02:00 CET, +1 -> +2 tran.atMSecsSinceEpoch = QDateTime(QDate(2011, 3, 27), QTime(2, 0), - Qt::OffsetFromUTC, 3600).toMSecsSinceEpoch(); + eastOneHour).toMSecsSinceEpoch(); tran.offsetFromUtc = 7200; tran.standardTimeOffset = 3600; tran.daylightTimeOffset = 3600; expected << tran; // 2011-10-30 03:00 CEST, +2 -> +1 tran.atMSecsSinceEpoch = QDateTime(QDate(2011, 10, 30), QTime(3, 0), - Qt::OffsetFromUTC, 2 * 3600).toMSecsSinceEpoch(); + QTimeZone::fromSecondsAheadOfUtc(2 * 3600) + ).toMSecsSinceEpoch(); tran.offsetFromUtc = 3600; tran.standardTimeOffset = 3600; tran.daylightTimeOffset = 0; @@ -1681,10 +1698,8 @@ void tst_QTimeZone::testCetPrivate(const QTimeZonePrivate &tzp) QTimeZonePrivate::DataList result = tzp.transitions(prev, std); QCOMPARE(result.size(), expected.size()); for (int i = 0; i < expected.size(); ++i) { - QCOMPARE(QDateTime::fromMSecsSinceEpoch(result.at(i).atMSecsSinceEpoch, - Qt::OffsetFromUTC, 3600), - QDateTime::fromMSecsSinceEpoch(expected.at(i).atMSecsSinceEpoch, - Qt::OffsetFromUTC, 3600)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(result.at(i).atMSecsSinceEpoch, eastOneHour), + QDateTime::fromMSecsSinceEpoch(expected.at(i).atMSecsSinceEpoch, eastOneHour)); QCOMPARE(result.at(i).offsetFromUtc, expected.at(i).offsetFromUtc); QCOMPARE(result.at(i).standardTimeOffset, expected.at(i).standardTimeOffset); QCOMPARE(result.at(i).daylightTimeOffset, expected.at(i).daylightTimeOffset); @@ -1698,10 +1713,13 @@ void tst_QTimeZone::testEpochTranPrivate(const QTimeZonePrivate &tzp) if (!tzp.hasTransitions()) return; // test only viable for transitions + const auto UTC = QTimeZone::UTC; + const auto hour = std::chrono::hours{1}; QTimeZonePrivate::Data tran = tzp.nextTransition(0); // i.e. first after epoch // 1970-04-26 02:00 EST, -5 -> -4 - const QDateTime after = QDateTime(QDate(1970, 4, 26), QTime(2, 0), Qt::OffsetFromUTC, -5 * 3600); - const QDateTime found = QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, Qt::UTC); + const QDateTime after = QDateTime(QDate(1970, 4, 26), QTime(2, 0), + QTimeZone::fromDurationAheadOfUtc(-5 * hour)); + const QDateTime found = QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, UTC); #ifdef USING_WIN_TZ // MS gets the date wrong: 5th April instead of 26th. QCOMPARE(found.toOffsetFromUtc(-5 * 3600).time(), after.time()); #else @@ -1712,16 +1730,16 @@ void tst_QTimeZone::testEpochTranPrivate(const QTimeZonePrivate &tzp) QCOMPARE(tran.daylightTimeOffset, 3600); // Pre-epoch time-zones might not be supported at all: - tran = tzp.nextTransition(QDateTime(QDate(1601, 1, 1), QTime(0, 0), - Qt::UTC).toMSecsSinceEpoch()); + tran = tzp.nextTransition(QDateTime(QDate(1601, 1, 1), QTime(0, 0), UTC).toMSecsSinceEpoch()); if (tran.atMSecsSinceEpoch != QTimeZonePrivate::invalidMSecs() // Toronto *did* have a transition before 1970 (DST since 1918): && tran.atMSecsSinceEpoch < 0) { // ... but, if they are, we should be able to search back to them: tran = tzp.previousTransition(0); // i.e. last before epoch // 1969-10-26 02:00 EDT, -4 -> -5 - QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, Qt::UTC), - QDateTime(QDate(1969, 10, 26), QTime(2, 0), Qt::OffsetFromUTC, -4 * 3600)); + QCOMPARE(QDateTime::fromMSecsSinceEpoch(tran.atMSecsSinceEpoch, UTC), + QDateTime(QDate(1969, 10, 26), QTime(2, 0), + QTimeZone::fromDurationAheadOfUtc(-4 * hour))); QCOMPARE(tran.offsetFromUtc, -5 * 3600); QCOMPARE(tran.standardTimeOffset, -5 * 3600); QCOMPARE(tran.daylightTimeOffset, 0); diff --git a/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp b/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp index ca648c051ed..3ba5b5fb9f9 100644 --- a/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp +++ b/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp @@ -390,7 +390,7 @@ void tst_QDateTime::equivalentUtc() { bool result = false; const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, QTimeZone::UTC); const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { for (const QDateTime &test : list) @@ -416,7 +416,7 @@ void tst_QDateTime::lessThanUtc() { bool result = false; const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, QTimeZone::UTC); const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { for (const QDateTime &test : list) @@ -500,7 +500,7 @@ void tst_QDateTime::fromMSecsSinceEpoch() const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; QBENCHMARK { for (int jd = start; jd < end; ++jd) - QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::LocalTime); + QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY); } } @@ -510,7 +510,7 @@ void tst_QDateTime::fromMSecsSinceEpochUtc() const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; QBENCHMARK { for (int jd = start; jd < end; ++jd) - QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::UTC); + QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, QTimeZone::UTC); } } diff --git a/tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp b/tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp index 8d34ca50a3f..0cd40658248 100644 --- a/tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp +++ b/tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp @@ -108,9 +108,9 @@ void tst_QTimeZone::transitionList() { QFETCH(QByteArray, name); const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); - const QDateTime early = QDate(1625, 6, 8).startOfDay(Qt::UTC); // Cassini's birth date + const QDateTime early = QDate(1625, 6, 8).startOfDay(QTimeZone::UTC); // Cassini's birth date const QDateTime late // End of 32-bit signed time_t - = QDateTime::fromSecsSinceEpoch(std::numeric_limits::max(), Qt::UTC); + = QDateTime::fromSecsSinceEpoch(std::numeric_limits::max(), QTimeZone::UTC); QTimeZone::OffsetDataList seq; QBENCHMARK { seq = zone.transitions(early, late); @@ -122,7 +122,7 @@ void tst_QTimeZone::transitionsForward() { QFETCH(QByteArray, name); const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); - const QDateTime early = QDate(1625, 6, 8).startOfDay(Qt::UTC); // Cassini's birth date + const QDateTime early = QDate(1625, 6, 8).startOfDay(QTimeZone::UTC); // Cassini's birth date QBENCHMARK { QTimeZone::OffsetData tran = zone.nextTransition(early); while (tran.atUtc.isValid()) @@ -135,7 +135,7 @@ void tst_QTimeZone::transitionsReverse() QFETCH(QByteArray, name); const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); const QDateTime late // End of 32-bit signed time_t - = QDateTime::fromSecsSinceEpoch(std::numeric_limits::max(), Qt::UTC); + = QDateTime::fromSecsSinceEpoch(std::numeric_limits::max(), QTimeZone::UTC); QBENCHMARK { QTimeZone::OffsetData tran = zone.previousTransition(late); while (tran.atUtc.isValid())