[Libreoffice-commits] core.git: sc/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Nov 16 12:55:04 UTC 2018


 sc/source/ui/docshell/impex.cxx |   12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

New commits:
commit 071eabe3e87a3bffd8710ebf1f1d51f15f230833
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Fri Nov 16 09:00:38 2018 +0100
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Fri Nov 16 13:54:39 2018 +0100

    Do not truncate fractions of seconds in timestamps to integral milliseconds
    
    I.e., importing a CSV field like "1970-01-01T00:00:45.890622" as "Date (YMD)"
    should not truncate .890622 to .891.
    
    Change-Id: I8d17ce54f63c3c4e68b8f90c63b6d1bb28bee67b
    Reviewed-on: https://gerrit.libreoffice.org/63459
    Tested-by: Jenkins
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 5f7e6375c7c0..a86fe777d6cd 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1162,16 +1162,18 @@ static bool lcl_PutString(
                 pCalendar->setValue( i18n::CalendarFieldIndex::DAY_OF_MONTH, nDay );
                 pCalendar->setValue( i18n::CalendarFieldIndex::MONTH, nMonth );
                 pCalendar->setValue( i18n::CalendarFieldIndex::YEAR, nYear );
-                sal_Int16 nHour, nMinute, nSecond, nMilli;
+                sal_Int16 nHour, nMinute, nSecond;
                 // #i14974# The imported value should have no fractional value, so set the
                 // time fields to zero (ICU calendar instance defaults to current date/time)
-                nHour = nMinute = nSecond = nMilli = 0;
+                nHour = nMinute = nSecond = 0;
                 if (nFound > 3)
                     nHour = static_cast<sal_Int16>(rStr.copy( nStart[3], nEnd[3]+1-nStart[3]).toInt32());
                 if (nFound > 4)
                     nMinute = static_cast<sal_Int16>(rStr.copy( nStart[4], nEnd[4]+1-nStart[4]).toInt32());
                 if (nFound > 5)
                     nSecond = static_cast<sal_Int16>(rStr.copy( nStart[5], nEnd[5]+1-nStart[5]).toInt32());
+                // do not use calendar's milliseconds, to avoid fractional part truncation
+                double fFrac = 0.0;
                 if (nFound > 6)
                 {
                     sal_Unicode cDec = '.';
@@ -1180,19 +1182,19 @@ static bool lcl_PutString(
                     rtl_math_ConversionStatus eStatus;
                     double fV = rtl::math::stringToDouble( aT, cDec, 0, &eStatus );
                     if (eStatus == rtl_math_ConversionStatus_Ok)
-                        nMilli = static_cast<sal_Int16>(1000.0 * fV + 0.5);
+                        fFrac = fV / 86400.0;
                 }
                 pCalendar->setValue( i18n::CalendarFieldIndex::HOUR, nHour );
                 pCalendar->setValue( i18n::CalendarFieldIndex::MINUTE, nMinute );
                 pCalendar->setValue( i18n::CalendarFieldIndex::SECOND, nSecond );
-                pCalendar->setValue( i18n::CalendarFieldIndex::MILLISECOND, nMilli );
+                pCalendar->setValue( i18n::CalendarFieldIndex::MILLISECOND, 0 );
                 if ( pCalendar->isValid() )
                 {
                     double fDiff = DateTime(pDocFormatter->GetNullDate()) -
                         pCalendar->getEpochStart();
                     // #i14974# must use getLocalDateTime to get the same
                     // date values as set above
-                    double fDays = pCalendar->getLocalDateTime();
+                    double fDays = pCalendar->getLocalDateTime() + fFrac;
                     fDays -= fDiff;
 
                     LanguageType eLatin, eCjk, eCtl;


More information about the Libreoffice-commits mailing list