[Libreoffice-commits] core.git: Branch 'libreoffice-4-1' - connectivity/source

Lionel Elie Mamane lionel at mamane.lu
Fri Jun 28 05:49:05 PDT 2013


 connectivity/source/commontools/dbconversion.cxx |   99 +++++++++--------------
 1 file changed, 42 insertions(+), 57 deletions(-)

New commits:
commit da76d753485ae1dc2c65778b96fa6ffa1258fc54
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Thu Jun 27 18:59:12 2013 +0200

    fix nanosecond computation
    
    when less/more than nine digits
    
    Change-Id: I222ae7c51e37468a01abc9caab91657ea2593d13
    Reviewed-on: https://gerrit.libreoffice.org/4592
    Reviewed-by: Fridrich Strba <fridrich at documentfoundation.org>
    Tested-by: Fridrich Strba <fridrich at documentfoundation.org>

diff --git a/connectivity/source/commontools/dbconversion.cxx b/connectivity/source/commontools/dbconversion.cxx
index f777420..73b7638 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 <unotools/datetime.hxx>
 #include <sstream>
 #include <iomanip>
 
@@ -56,6 +57,7 @@ namespace dbtools
     using namespace ::comphelper;
     using namespace ::com::sun::star::uno;
     using namespace ::com::sun::star::util;
+    namespace utl = ::com::sun::star::util;
     using namespace ::com::sun::star::sdb;
     using namespace ::com::sun::star::sdbc;
     using namespace ::com::sun::star::lang;
@@ -69,7 +71,7 @@ namespace dbtools
         return STANDARD_DB_DATE;
     }
     //------------------------------------------------------------------------------
-    OUString DBTypeConversion::toDateString(const Date& rDate)
+    OUString DBTypeConversion::toDateString(const utl::Date& rDate)
     {
         sal_Char s[11];
         snprintf(s,
@@ -82,7 +84,7 @@ namespace dbtools
         return OUString::createFromAscii(s);
     }
     //------------------------------------------------------------------
-    OUString DBTypeConversion::toTimeString(const Time& rTime)
+    OUString DBTypeConversion::toTimeString(const utl::Time& rTime)
     {
         std::ostringstream ostr;
         using std::setw;
@@ -95,19 +97,19 @@ namespace dbtools
     }
 
     //------------------------------------------------------------------
-    OUString DBTypeConversion::toDateTimeString(const DateTime& _rDateTime)
+    OUString DBTypeConversion::toDateTimeString(const utl::DateTime& _rDateTime)
     {
-        Date aDate(_rDateTime.Day,_rDateTime.Month,_rDateTime.Year);
+        utl::Date aDate(_rDateTime.Day,_rDateTime.Month,_rDateTime.Year);
         OUStringBuffer aTemp(toDateString(aDate));
         aTemp.appendAscii(" ");
-        Time aTime(_rDateTime.NanoSeconds,_rDateTime.Seconds,_rDateTime.Minutes,_rDateTime.Hours);
+        utl::Time aTime(_rDateTime.NanoSeconds,_rDateTime.Seconds,_rDateTime.Minutes,_rDateTime.Hours);
         aTemp.append( toTimeString(aTime) );
         return  aTemp.makeStringAndClear();
     }
     //------------------------------------------------------------------------------
-    Date DBTypeConversion::toDate(sal_Int32 _nVal)
+    utl::Date DBTypeConversion::toDate(sal_Int32 _nVal)
     {
-        Date aReturn;
+        utl::Date aReturn;
         aReturn.Day = (sal_uInt16)(_nVal % 100);
         aReturn.Month = (sal_uInt16)((_nVal  / 100) % 100);
         aReturn.Year = (sal_uInt16)(_nVal  / 10000);
@@ -115,9 +117,9 @@ namespace dbtools
     }
 
     //------------------------------------------------------------------------------
-    Time DBTypeConversion::toTime(sal_Int64 _nVal)
+    utl::Time DBTypeConversion::toTime(sal_Int64 _nVal)
     {
-        Time aReturn;
+        utl::Time aReturn;
         sal_uInt64 unVal = static_cast<sal_uInt64>(_nVal >= 0 ? _nVal : -_nVal);
         aReturn.Hours = unVal / hourMask;
         aReturn.Minutes = (unVal / minMask) % 100;
@@ -127,7 +129,7 @@ namespace dbtools
     }
 
     //------------------------------------------------------------------------------
-    sal_Int32 DBTypeConversion::toINT32(const Date& rVal)
+    sal_Int32 DBTypeConversion::toINT32(const utl::Date& rVal)
     {
         return ((sal_Int32)(rVal.Day%100)) +
             (((sal_Int32)(rVal.Month%100))*100) +
@@ -135,7 +137,7 @@ namespace dbtools
     }
 
     //------------------------------------------------------------------------------
-    sal_Int64 DBTypeConversion::toINT64(const Time& rVal)
+    sal_Int64 DBTypeConversion::toINT64(const utl::Time& rVal)
     {
         // normalize time
         sal_Int32 nSeconds          = rVal.Seconds + rVal.NanoSeconds / nanoSecInSec;
@@ -153,7 +155,7 @@ namespace dbtools
     }
 
     //------------------------------------------------------------------------------
-    sal_Int32 DBTypeConversion::getMsFromTime(const Time& rVal)
+    sal_Int32 DBTypeConversion::getMsFromTime(const utl::Time& rVal)
     {
         sal_Int32   nHour     = rVal.Hours;
         sal_Int32   nMin      = rVal.Minutes;
@@ -164,7 +166,7 @@ namespace dbtools
     }
 
     //------------------------------------------------------------------------------
-    sal_Int64 DBTypeConversion::getNsFromTime(const Time& rVal)
+    sal_Int64 DBTypeConversion::getNsFromTime(const utl::Time& rVal)
     {
         sal_Int32   nHour     = rVal.Hours;
         sal_Int32   nMin      = rVal.Minutes;
@@ -208,7 +210,7 @@ namespace dbtools
     }
 
     //------------------------------------------------------------------------------
-    static sal_Int32 implRelativeToAbsoluteNull(const Date& _rDate)
+    static sal_Int32 implRelativeToAbsoluteNull(const utl::Date& _rDate)
     {
         sal_Int32 nDays = 0;
 
@@ -266,28 +268,28 @@ namespace dbtools
         rDay = (sal_uInt16)nTempDays;
     }
     //------------------------------------------------------------------------------
-    sal_Int32 DBTypeConversion::toDays(const Date& _rVal, const Date& _rNullDate)
+    sal_Int32 DBTypeConversion::toDays(const utl::Date& _rVal, const utl::Date& _rNullDate)
     {
         return implRelativeToAbsoluteNull(_rVal) - implRelativeToAbsoluteNull(_rNullDate);
     }
 
     //------------------------------------------------------------------------------
-    double DBTypeConversion::toDouble(const Date& rVal, const Date& _rNullDate)
+    double DBTypeConversion::toDouble(const utl::Date& rVal, const utl::Date& _rNullDate)
     {
         return (double)toDays(rVal, _rNullDate);
     }
 
     //------------------------------------------------------------------------------
-    double DBTypeConversion::toDouble(const Time& rVal)
+    double DBTypeConversion::toDouble(const utl::Time& rVal)
     {
         return (double)getNsFromTime(rVal) / fNanoSecondsPerDay;
     }
 
     //------------------------------------------------------------------------------
-    double DBTypeConversion::toDouble(const DateTime& _rVal, const Date& _rNullDate)
+    double DBTypeConversion::toDouble(const utl::DateTime& _rVal, const utl::Date& _rNullDate)
     {
-        sal_Int64   nTime     = toDays(Date(_rVal.Day, _rVal.Month, _rVal.Year), _rNullDate);
-        Time aTimePart;
+        sal_Int64   nTime     = toDays(utl::Date(_rVal.Day, _rVal.Month, _rVal.Year), _rNullDate);
+        utl::Time aTimePart;
 
         aTimePart.Hours             = _rVal.Hours;
         aTimePart.Minutes           = _rVal.Minutes;
@@ -297,7 +299,7 @@ namespace dbtools
         return ((double)nTime) + toDouble(aTimePart);
     }
     // -------------------------------------------------------------------------
-    static void addDays(sal_Int32 nDays, Date& _rDate)
+    static void addDays(sal_Int32 nDays, utl::Date& _rDate)
     {
         sal_Int32   nTempDays = implRelativeToAbsoluteNull( _rDate );
 
@@ -318,7 +320,7 @@ namespace dbtools
             implBuildFromRelative( nTempDays, _rDate.Day, _rDate.Month, _rDate.Year );
     }
     // -----------------------------------------------------------------------
-    static void subDays( sal_Int32 nDays, Date& _rDate )
+    static void subDays( sal_Int32 nDays, utl::Date& _rDate )
     {
         sal_Int32   nTempDays = implRelativeToAbsoluteNull( _rDate );
 
@@ -339,9 +341,9 @@ namespace dbtools
             implBuildFromRelative( nTempDays, _rDate.Day, _rDate.Month, _rDate.Year );
     }
     // -------------------------------------------------------------------------
-    Date DBTypeConversion::toDate(double dVal, const Date& _rNullDate)
+    utl::Date DBTypeConversion::toDate(double dVal, const utl::Date& _rNullDate)
     {
-        Date aRet = _rNullDate;
+        utl::Date aRet = _rNullDate;
 
         if (dVal >= 0)
             addDays((sal_Int32)dVal,aRet);
@@ -352,7 +354,7 @@ namespace dbtools
         return aRet;
     }
     // -------------------------------------------------------------------------
-    Time DBTypeConversion::toTime(double dVal)
+    utl::Time DBTypeConversion::toTime(double dVal)
     {
         sal_Int32 nDays     = (sal_Int32)dVal;
         sal_Int64 nNS = static_cast<sal_Int64>((dVal - (double)nDays) * fNanoSecondsPerDay + 0.5);
@@ -366,7 +368,7 @@ namespace dbtools
         else
             nSign = 1;
 
-        Time xRet;
+        utl::Time xRet;
         // normalize time
         // we have to sal_Int32 here because otherwise we get an overflow
         sal_Int64 nNanoSeconds      = nNS;
@@ -395,12 +397,12 @@ namespace dbtools
         return xRet;
     }
     //------------------------------------------------------------------------------
-    DateTime DBTypeConversion::toDateTime(double dVal, const Date& _rNullDate)
+    utl::DateTime DBTypeConversion::toDateTime(double dVal, const utl::Date& _rNullDate)
     {
-        Date aDate = toDate(dVal, _rNullDate);
-        Time aTime = toTime(dVal);
+        utl::Date aDate = toDate(dVal, _rNullDate);
+        utl::Time aTime = toTime(dVal);
 
-        DateTime xRet;
+        utl::DateTime xRet;
 
         xRet.Day          = aDate.Day;
         xRet.Month        = aDate.Month;
@@ -415,7 +417,7 @@ namespace dbtools
         return xRet;
     }
     //------------------------------------------------------------------------------
-    Date DBTypeConversion::toDate(const OUString& _sSQLString)
+    utl::Date DBTypeConversion::toDate(const OUString& _sSQLString)
     {
         // get the token out of a string
         static sal_Unicode sDateSep = '-';
@@ -432,50 +434,33 @@ namespace dbtools
                 nDay = (sal_uInt16)_sSQLString.getToken(0,sDateSep,nIndex).toInt32();
         }
 
-        return Date(nDay,nMonth,nYear);
+        return utl::Date(nDay,nMonth,nYear);
     }
 
     //-----------------------------------------------------------------------------
-    DateTime DBTypeConversion::toDateTime(const OUString& _sSQLString)
+    utl::DateTime DBTypeConversion::toDateTime(const OUString& _sSQLString)
     {
         //@see http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Timestamp.html#valueOf(java.lang.String)
         //@see http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Date.html#valueOf(java.lang.String)
         //@see http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Time.html#valueOf(java.lang.String)
 
         // the date part
-        Date aDate = toDate(_sSQLString);
-        Time aTime;
+        utl::Date aDate = toDate(_sSQLString);
+        utl::Time aTime;
         sal_Int32 nSeparation = _sSQLString.indexOf( ' ' );
         if ( -1 != nSeparation )
             aTime = toTime( _sSQLString.copy( nSeparation ) );
 
-        return DateTime(aTime.NanoSeconds, aTime.Seconds, aTime.Minutes, aTime.Hours,
+        return utl::DateTime(aTime.NanoSeconds, aTime.Seconds, aTime.Minutes, aTime.Hours,
                         aDate.Day, aDate.Month, aDate.Year);
     }
 
     //-----------------------------------------------------------------------------
-    Time DBTypeConversion::toTime(const OUString& _sSQLString)
+    utl::Time DBTypeConversion::toTime(const OUString& _sSQLString)
     {
-        static sal_Unicode sTimeSep = ':';
-
-        sal_Int32 nIndex    = 0;
-        sal_uInt16  nHour   = 0,
-                    nMinute = 0,
-                    nSecond = 0;
-        sal_uInt32  nNanoSeconds = 0;
-        nHour   = (sal_uInt16)_sSQLString.getToken(0,sTimeSep,nIndex).toInt32();
-        if(nIndex != -1)
-        {
-            nMinute = (sal_uInt16)_sSQLString.getToken(0,sTimeSep,nIndex).toInt32();
-            if(nIndex != -1)
-            {
-                nSecond = (sal_uInt16)_sSQLString.getToken(0,sTimeSep,nIndex).toInt32();
-                nIndex = 0;
-                OUString sNano(_sSQLString.getToken(1,'.',nIndex));
-                nNanoSeconds = sNano.toInt32();
-            }
-        }
-        return Time(nNanoSeconds, nSecond, nMinute, nHour);
+        utl::Time aTime;
+        ::utl::ISO8601parseTime(_sSQLString, aTime);
+        return aTime;
     }
 
 //.........................................................................


More information about the Libreoffice-commits mailing list