Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix QDateTime performance on Qt6 #323

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions QXlsx/source/xlsxutility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,33 @@ double timeToNumber(const QTime &time)
return QTime(0, 0).msecsTo(time) / (1000 * 60 * 60 * 24.0);
}

#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
static qint64 msecs1904 = QDateTime(QDate(1904, 1, 1), QTime(0, 0)).toMSecsSinceEpoch();
static qint64 msecs1899 = QDateTime(QDate(1899, 12, 31), QTime(0, 0)).toMSecsSinceEpoch();
#endif

QVariant datetimeFromNumber(double num, bool is1904)
{
QDateTime dtRet; // return value

if (!is1904 && num > 60) // for mac os excel
{
num = num - 1;
}

qint64 msecs = static_cast<qint64>(num * 1000 * 60 * 60 * 24.0 + 0.5);

#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
if (is1904)
msecs += msecs1904;
else
msecs += msecs1899;

QDateTime dtRet = QDateTime::fromMSecsSinceEpoch(msecs);
#else
QDateTime dtRet; // return value
QDateTime epoch(is1904 ? QDate(1904, 1, 1) : QDate(1899, 12, 31), QTime(0, 0));
QDateTime dtOld = epoch.addMSecs(msecs);
dtRet = dtOld;

#endif
// Remove one hour to see whether the date is Daylight
QDateTime dtNew = dtRet.addMSecs(-3600000); // issue102
if (dtNew.isDaylightTime()) {
Expand Down