kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0084-fdo-72916-correct-rounding-of-time-part-of-DateTime.patch

f0633d
From 56381a9b28dbe4caf6e3d0a92dfddcddcebe3494 Mon Sep 17 00:00:00 2001
f0633d
From: Lionel Elie Mamane <lionel@mamane.lu>
f0633d
Date: Sat, 21 Dec 2013 10:37:11 +0100
f0633d
Subject: [PATCH 084/109] fdo#72916 correct rounding of time part of DateTime
f0633d
f0633d
Change-Id: I135478755f9e5a844119129b470fef8de2cd0409
f0633d
---
f0633d
 connectivity/source/commontools/dbconversion.cxx | 16 +++++++++++++---
f0633d
 include/connectivity/dbconversion.hxx            |  2 +-
f0633d
 2 files changed, 14 insertions(+), 4 deletions(-)
f0633d
f0633d
diff --git a/connectivity/source/commontools/dbconversion.cxx b/connectivity/source/commontools/dbconversion.cxx
f0633d
index 847f45f..15276a6 100644
f0633d
--- a/connectivity/source/commontools/dbconversion.cxx
f0633d
+++ b/connectivity/source/commontools/dbconversion.cxx
f0633d
@@ -28,6 +28,7 @@
f0633d
 #include <com/sun/star/util/Time.hpp>
f0633d
 #include <com/sun/star/util/DateTime.hpp>
f0633d
 #include <rtl/ustrbuf.hxx>
f0633d
+#include <rtl/math.hxx>
f0633d
 #include <unotools/datetime.hxx>
f0633d
 #include <sstream>
f0633d
 #include <iomanip>
f0633d
@@ -355,10 +356,15 @@ namespace dbtools
f0633d
         return aRet;
f0633d
     }
f0633d
     // -------------------------------------------------------------------------
f0633d
-    utl::Time DBTypeConversion::toTime(double dVal)
f0633d
+    utl::Time DBTypeConversion::toTime(double dVal, short nDigits)
f0633d
     {
f0633d
         sal_Int32 nDays     = (sal_Int32)dVal;
f0633d
-        sal_Int64 nNS = static_cast<sal_Int64>((dVal - (double)nDays) * fNanoSecondsPerDay + 0.5);
f0633d
+        sal_Int64 nNS;
f0633d
+        {
f0633d
+            double fSeconds((dVal - (double)nDays) * (fNanoSecondsPerDay / nanoSecInSec));
f0633d
+            fSeconds = ::rtl::math::round( fSeconds, nDigits );
f0633d
+            nNS = fSeconds * nanoSecInSec;
f0633d
+        }
f0633d
 
f0633d
         sal_Int16 nSign;
f0633d
         if ( nNS < 0 )
f0633d
@@ -401,7 +407,11 @@ namespace dbtools
f0633d
     utl::DateTime DBTypeConversion::toDateTime(double dVal, const utl::Date& _rNullDate)
f0633d
     {
f0633d
         utl::Date aDate = toDate(dVal, _rNullDate);
f0633d
-        utl::Time aTime = toTime(dVal);
f0633d
+        // there is not enough precision in a double to have both a date
f0633d
+        // and a time up to nanoseconds -> limit to microseconds to have
f0633d
+        // correct rounding, that is e.g. 13:00:00.000000000 instead of
f0633d
+        // 12:59:59.999999790
f0633d
+        utl::Time aTime = toTime(dVal, 6);
f0633d
 
f0633d
         utl::DateTime xRet;
f0633d
 
f0633d
diff --git a/include/connectivity/dbconversion.hxx b/include/connectivity/dbconversion.hxx
f0633d
index 9536c79..b11442b 100644
f0633d
--- a/include/connectivity/dbconversion.hxx
f0633d
+++ b/include/connectivity/dbconversion.hxx
f0633d
@@ -105,7 +105,7 @@ namespace dbtools
f0633d
 
f0633d
         static ::com::sun::star::util::Date     toDate(double dVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
f0633d
         static ::com::sun::star::util::Date     toDate(const OUString& _sSQLDate);
f0633d
-        static ::com::sun::star::util::Time     toTime(double dVal);
f0633d
+        static ::com::sun::star::util::Time     toTime(double dVal, short nDigits = 9);
f0633d
         static ::com::sun::star::util::Time     toTime(const OUString& _sSQLDate);
f0633d
         static ::com::sun::star::util::DateTime toDateTime(double dVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
f0633d
         static ::com::sun::star::util::DateTime toDateTime(const OUString& _sSQLDate);
f0633d
-- 
f0633d
1.8.4.2
f0633d