summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qcore_foundation.mm
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2016-09-30 11:50:49 +0200
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2016-10-02 13:07:18 +0000
commitbe7f671ac99c7d02d82a5f05822642bd39e30923 (patch)
tree568a67ddf46b3efa8c7714ad8050c3d9950335ac /src/corelib/kernel/qcore_foundation.mm
parentc6fa0222e2c140eebd0322e550780afef1bc26f7 (diff)
Round to nearest millisecond in QDateTime::fromCFDate()
CFAbsoluteTime is measured in seconds, represented by a double, so when converting milliseconds to CFAbsoluteTime we may get a slight error due to missing precision in double to represent the milliseconds exactly. By rounding to the closest millisecond when converting back, we avoid truncating and being one ms off. Change-Id: If1e99f97b000fb8cb893ddfc5d7ba81096c0ea88 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/corelib/kernel/qcore_foundation.mm')
-rw-r--r--src/corelib/kernel/qcore_foundation.mm6
1 files changed, 3 insertions, 3 deletions
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<qint64>((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<qint64>([date timeIntervalSince1970] * 1000));
+ return QDateTime::fromMSecsSinceEpoch(qRound64([date timeIntervalSince1970] * 1000));
}
/*!