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