diff --git a/quazip/quazip_qt_compat.h b/quazip/quazip_qt_compat.h index a72dcea..0dde011 100644 --- a/quazip/quazip_qt_compat.h +++ b/quazip/quazip_qt_compat.h @@ -103,16 +103,36 @@ inline QString quazip_symlink_target(const QFileInfo &fi) { } #endif +// deprecation +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) +#include +inline QDateTime quazip_since_epoch() { + return QDateTime(QDate(1970, 1, 1), QTime(0, 0), QTimeZone::utc()); +} + +inline QDateTime quazip_since_epoch_ntfs() { + return QDateTime(QDate(1601, 1, 1), QTime(0, 0), QTimeZone::utc()); +} +#else +inline QDateTime quazip_since_epoch() { + return QDateTime(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC); +} + +inline QDateTime quazip_since_epoch_ntfs() { + return QDateTime(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); +} +#endif + // this is not a deprecation but an improvement, for a change #include #if (QT_VERSION >= 0x040700) inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) { - QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime base = quazip_since_epoch_ntfs(); return base.msecsTo(time) * 10000 + fineTicks; } #else inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) { - QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime base = quazip_since_epoch_ntfs(); QDateTime utc = time.toUTC(); return (static_cast(base.date().daysTo(utc.date())) * Q_INT64_C(86400000) diff --git a/quazip/quazipfileinfo.cpp b/quazip/quazipfileinfo.cpp index c27ba37..f182f74 100644 --- a/quazip/quazipfileinfo.cpp +++ b/quazip/quazipfileinfo.cpp @@ -24,6 +24,8 @@ see quazip/(un)zip.h files for details. Basically it's the zlib license. #include "quazipfileinfo.h" +#include "quazip_qt_compat.h" + #include static QFile::Permissions permissionsFromExternalAttr(quint32 externalAttr) { @@ -123,7 +125,7 @@ static QDateTime getNTFSTime(const QByteArray &extra, int position, timeReader >> time; if (time == 0) return dateTime; - QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime base = quazip_since_epoch_ntfs(); dateTime = base.addMSecs(time / 10000); if (fineTicks != nullptr) { *fineTicks = static_cast(time % 10000); @@ -167,7 +169,7 @@ QDateTime QuaZipFileInfo64::getExtTime(const QByteArray &extra, int flag) qint32 time; input >> time; if (nextFlag == flag) { - QDateTime base(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime base = quazip_since_epoch(); dateTime = base.addSecs(time); return dateTime; } diff --git a/qztest/testquazipfileinfo.cpp b/qztest/testquazipfileinfo.cpp index be174a1..7470167 100644 --- a/qztest/testquazipfileinfo.cpp +++ b/qztest/testquazipfileinfo.cpp @@ -36,7 +36,7 @@ void TestQuaZipFileInfo::getNTFSTime() if (!createTestFiles(testFiles)) { QFAIL("Can't create test file"); } - QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime base(QDate(1601, 1, 1), QTime(0, 0), QTimeZone::utc()); quint64 mTicks, aTicks, cTicks; QFileInfo fileInfo("tmp/test.txt"); { @@ -149,25 +149,25 @@ void TestQuaZipFileInfo::getExtTime_data() << (QList() << 1 << 2 << 3) << static_cast(5) << (QList() << 1) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), Qt::UTC) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 2), Qt::UTC) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 3), Qt::UTC); + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), QTimeZone::utc()) + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 2), QTimeZone::utc()) + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 3), QTimeZone::utc()); QTest::newRow("no ac time") << QString::fromUtf8("noAcTime") << static_cast(5) << static_cast(9) << (QList() << 1 << 3) << static_cast(5) << (QList() << 1) - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), Qt::UTC) + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 1), QTimeZone::utc()) << QDateTime() - << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 3), Qt::UTC); + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 3), QTimeZone::utc()); QTest::newRow("negativeTime") << QString::fromUtf8("negativeTime") << static_cast(1) << static_cast(5) << (QList() << -1) << static_cast(5) << (QList() << -1) - << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), Qt::UTC) + << QDateTime(QDate(1969, 12, 31), QTime(23, 59, 59), QTimeZone::utc()) << QDateTime() << QDateTime(); } @@ -254,7 +254,7 @@ void TestQuaZipFileInfo::getExtTime_issue43() QDateTime actualLocalAcTime = zipFile.getExtAcTime(); QDateTime actualLocalCrTime = zipFile.getExtCrTime(); zip.close(); - QDateTime extModTime(QDate(2019, 7, 2), QTime(15, 43, 47), Qt::UTC); + QDateTime extModTime(QDate(2019, 7, 2), QTime(15, 43, 47), QTimeZone::utc()); QDateTime extAcTime = extModTime; QDateTime extCrTime = extModTime; QCOMPARE(actualGlobalModTime, extModTime); diff --git a/qztest/testquazipnewinfo.cpp b/qztest/testquazipnewinfo.cpp index 98f1e37..ec5cd75 100644 --- a/qztest/testquazipnewinfo.cpp +++ b/qztest/testquazipnewinfo.cpp @@ -25,7 +25,7 @@ void TestQuaZipNewInfo::setFileNTFSTimes() if (!createTestFiles(testFiles)) { QFAIL("Can't create test file"); } - QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC); + QDateTime base(QDate(1601, 1, 1), QTime(0, 0), QTimeZone::utc()); quint64 mTicks, aTicks, cTicks; { // create