diff --git a/src/corelib/kernel/qcore_foundation.mm b/src/corelib/kernel/qcore_foundation.mm index 2291017a5d..f5ccd1c1f2 100644 --- a/src/corelib/kernel/qcore_foundation.mm +++ b/src/corelib/kernel/qcore_foundation.mm @@ -375,8 +375,8 @@ QDateTime QDateTime::fromCFDate(CFDateRef date) { if (!date) return QDateTime(); - return QDateTime::fromMSecsSinceEpoch(static_cast((CFDateGetAbsoluteTime(date) - + kCFAbsoluteTimeIntervalSince1970) * 1000)); + CFAbsoluteTime sSinceEpoch = kCFAbsoluteTimeIntervalSince1970 + CFDateGetAbsoluteTime(date); + return QDateTime::fromMSecsSinceEpoch(qRound64(sSinceEpoch * 1000)); } /*! @@ -404,7 +404,7 @@ QDateTime QDateTime::fromNSDate(const NSDate *date) { if (!date) return QDateTime(); - return QDateTime::fromMSecsSinceEpoch(static_cast([date timeIntervalSince1970] * 1000)); + return QDateTime::fromMSecsSinceEpoch(qRound64([date timeIntervalSince1970] * 1000)); } /*! diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm index fb49b8952e..f73c7b9d5d 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm @@ -36,8 +36,11 @@ void tst_QDateTime_macTypes() { // QDateTime <-> CFDate - { - QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0); + + static const int kMsPerSecond = 1000; + + for (int i = 0; i < kMsPerSecond; ++i) { + QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(i); const CFDateRef cfDate = qtDateTime.toCFDate(); QCOMPARE(QDateTime::fromCFDate(cfDate), qtDateTime); CFRelease(cfDate); @@ -50,9 +53,9 @@ void tst_QDateTime_macTypes() QCOMPARE(QDateTime::fromCFDate(cfDate), qtDateTimeCopy); } // QDateTime <-> NSDate - { + for (int i = 0; i < kMsPerSecond; ++i) { QMacAutoReleasePool pool; - QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0); + QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(i); const NSDate *nsDate = qtDateTime.toNSDate(); QCOMPARE(QDateTime::fromNSDate(nsDate), qtDateTime); }