diff options
131 files changed, 1309 insertions, 898 deletions
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 0f5f76da4dce..b5da3b18c9af 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -3051,7 +3051,7 @@ RTLFUNC(FileDateTime) try { util::DateTime aUnoDT = xSFI->getDateTimeModified( aPath ); - aTime = Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ); + aTime = Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.NanoSeconds ); aDate = Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ); } catch(const Exception & ) diff --git a/comphelper/source/misc/anycompare.cxx b/comphelper/source/misc/anycompare.cxx index 470be26794ce..775386e9c083 100644 --- a/comphelper/source/misc/anycompare.cxx +++ b/comphelper/source/misc/anycompare.cxx @@ -116,7 +116,7 @@ namespace comphelper if ( lhs.Seconds > rhs.Seconds ) return false; - if ( lhs.HundredthSeconds < rhs.HundredthSeconds ) + if ( lhs.NanoSeconds < rhs.NanoSeconds ) return true; return false; } @@ -166,7 +166,7 @@ namespace comphelper if ( lhs.Seconds > rhs.Seconds ) return false; - if ( lhs.HundredthSeconds < rhs.HundredthSeconds ) + if ( lhs.NanoSeconds < rhs.NanoSeconds ) return true; return false; } diff --git a/comphelper/source/misc/types.cxx b/comphelper/source/misc/types.cxx index e77176fb2351..fbf49f3a9408 100644 --- a/comphelper/source/misc/types.cxx +++ b/comphelper/source/misc/types.cxx @@ -44,7 +44,7 @@ using namespace ::com::sun::star::lang; //------------------------------------------------------------------------- sal_Bool operator ==(const DateTime& _rLeft, const DateTime& _rRight) { - return ( _rLeft.HundredthSeconds == _rRight.HundredthSeconds) && + return ( _rLeft.NanoSeconds == _rRight.NanoSeconds) && ( _rLeft.Seconds == _rRight.Seconds) && ( _rLeft.Minutes == _rRight.Minutes) && ( _rLeft.Hours == _rRight.Hours) && @@ -64,7 +64,7 @@ sal_Bool operator ==(const Date& _rLeft, const Date& _rRight) //------------------------------------------------------------------------- sal_Bool operator ==(const Time& _rLeft, const Time& _rRight) { - return ( _rLeft.HundredthSeconds == _rRight.HundredthSeconds) && + return ( _rLeft.NanoSeconds == _rRight.NanoSeconds) && ( _rLeft.Seconds == _rRight.Seconds) && ( _rLeft.Minutes == _rRight.Minutes) && ( _rLeft.Hours == _rRight.Hours) ; diff --git a/connectivity/inc/connectivity/dbconversion.hxx b/connectivity/inc/connectivity/dbconversion.hxx index e8516d1fcd35..9536c799ec81 100644 --- a/connectivity/inc/connectivity/dbconversion.hxx +++ b/connectivity/inc/connectivity/dbconversion.hxx @@ -111,7 +111,9 @@ namespace dbtools static ::com::sun::star::util::DateTime toDateTime(const OUString& _sSQLDate); + // TODO: consider removing getMsFromTime static sal_Int32 getMsFromTime(const ::com::sun::star::util::Time& rVal); + static sal_Int64 getNsFromTime(const ::com::sun::star::util::Time& rVal); static sal_Int32 toDays(const ::com::sun::star::util::Date& _rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate()); @@ -120,10 +122,10 @@ namespace dbtools static double toDouble(const ::com::sun::star::util::DateTime& rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate()); static sal_Int32 toINT32(const ::com::sun::star::util::Date& rVal); - static sal_Int32 toINT32(const ::com::sun::star::util::Time& rVal); + static sal_Int64 toINT64(const ::com::sun::star::util::Time& rVal); static ::com::sun::star::util::Date toDate(sal_Int32 _nVal); - static ::com::sun::star::util::Time toTime(sal_Int32 _nVal); + static ::com::sun::star::util::Time toTime(sal_Int64 _nVal); /** convert a double which is a date value relative to a given fixed date into a date value relative to the standard db null date. @@ -139,9 +141,9 @@ namespace dbtools // return the date in the format %04d-%02d-%02d static OUString toDateString(const ::com::sun::star::util::Date& rDate); - // return the time in the format %02d:%02d:%02d + // return the time in the format %02d:%02d:%02d.%09d static OUString toTimeString(const ::com::sun::star::util::Time& rTime); - // return the DateTime in the format %04d-%02d-%02d %02d:%02d:%02d + // return the DateTime in the format %04d-%02d-%02d %02d:%02d:%02d.%09d static OUString toDateTimeString(const ::com::sun::star::util::DateTime& _rDateTime); // return the any in an sql standard format static OUString toSQLString(sal_Int32 eType, const ::com::sun::star::uno::Any& _rVal, sal_Bool bQuote, diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx index ef968fb9261e..770b34ea43c9 100644 --- a/connectivity/source/commontools/FValue.cxx +++ b/connectivity/source/commontools/FValue.cxx @@ -746,14 +746,14 @@ bool operator==(const Date& _rLH,const Date& _rRH) bool operator==(const Time& _rLH,const Time& _rRH) { - return _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.HundredthSeconds == _rRH.HundredthSeconds; + return _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.NanoSeconds == _rRH.NanoSeconds; } // ------------------------------------------------------------------------- bool operator==(const DateTime& _rLH,const DateTime& _rRH) { return _rLH.Day == _rRH.Day && _rLH.Month == _rRH.Month && _rLH.Year == _rRH.Year && - _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.HundredthSeconds == _rRH.HundredthSeconds; + _rLH.Minutes == _rRH.Minutes && _rLH.Hours == _rRH.Hours && _rLH.Seconds == _rRH.Seconds && _rLH.NanoSeconds == _rRH.NanoSeconds; } // ------------------------------------------------------------------------- @@ -2020,7 +2020,7 @@ Sequence<sal_Int8> ORowSetValue::getSequence() const case DataType::TIMESTAMP: { ::com::sun::star::util::DateTime* pDateTime = static_cast< ::com::sun::star::util::DateTime*>(m_aValue.m_pValue); - aValue.HundredthSeconds = pDateTime->HundredthSeconds; + aValue.NanoSeconds = pDateTime->NanoSeconds; aValue.Seconds = pDateTime->Seconds; aValue.Minutes = pDateTime->Minutes; aValue.Hours = pDateTime->Hours; @@ -2073,7 +2073,7 @@ Sequence<sal_Int8> ORowSetValue::getSequence() const case DataType::TIME: { ::com::sun::star::util::Time* pTime = static_cast< ::com::sun::star::util::Time*>(m_aValue.m_pValue); - aValue.HundredthSeconds = pTime->HundredthSeconds; + aValue.NanoSeconds = pTime->NanoSeconds; aValue.Seconds = pTime->Seconds; aValue.Minutes = pTime->Minutes; aValue.Hours = pTime->Hours; diff --git a/connectivity/source/commontools/dbconversion.cxx b/connectivity/source/commontools/dbconversion.cxx index 0af54185befd..cb8715102864 100644 --- a/connectivity/source/commontools/dbconversion.cxx +++ b/connectivity/source/commontools/dbconversion.cxx @@ -31,6 +31,20 @@ #define MAX_DAYS 3636532 +namespace +{ + const double fMilliSecondsPerDay = 86400000.0; + const sal_Int64 nanoSecInSec = 1000000000; + const sal_Int16 secInMin = 60; + const sal_Int16 minInHour = 60; + + const sal_Int64 secMask = 1000000000; + const sal_Int64 minMask = 100000000000; + const sal_Int64 hourMask = 10000000000000; + + const double fNanoSecondsPerDay = nanoSecInSec * secInMin * minInHour * 24.0; +} + //......................................................................... namespace dbtools { @@ -68,14 +82,15 @@ namespace dbtools //------------------------------------------------------------------ OUString DBTypeConversion::toTimeString(const Time& rTime) { - sal_Char s[9]; + const size_t buflen = 19; + sal_Char s[buflen]; snprintf(s, - sizeof(s), - "%02d:%02d:%02d", - (int)rTime.Hours, - (int)rTime.Minutes, - (int)rTime.Seconds); - s[8] = 0; + buflen, + "%02d:%02d:%02d.%09d", + rTime.Hours, + rTime.Minutes, + rTime.Seconds, + rTime.NanoSeconds); return OUString::createFromAscii(s); } @@ -85,10 +100,8 @@ namespace dbtools Date aDate(_rDateTime.Day,_rDateTime.Month,_rDateTime.Year); OUStringBuffer aTemp(toDateString(aDate)); aTemp.appendAscii(" "); - Time aTime(0,_rDateTime.Seconds,_rDateTime.Minutes,_rDateTime.Hours); + Time aTime(_rDateTime.NanoSeconds,_rDateTime.Seconds,_rDateTime.Minutes,_rDateTime.Hours); aTemp.append( toTimeString(aTime) ); - aTemp.appendAscii("."); - aTemp.append( static_cast<sal_Int32>(_rDateTime.HundredthSeconds)); return aTemp.makeStringAndClear(); } //------------------------------------------------------------------------------ @@ -102,17 +115,17 @@ namespace dbtools } //------------------------------------------------------------------------------ - Time DBTypeConversion::toTime(sal_Int32 _nVal) + Time DBTypeConversion::toTime(sal_Int64 _nVal) { Time aReturn; - aReturn.Hours = (sal_uInt16)(((sal_uInt32)(_nVal >= 0 ? _nVal : _nVal*-1)) / 1000000); - aReturn.Minutes = (sal_uInt16)((((sal_uInt32)(_nVal >= 0 ? _nVal : _nVal*-1)) / 10000) % 100); - aReturn.Seconds = (sal_uInt16)((((sal_uInt32)(_nVal >= 0 ? _nVal : _nVal*-1)) / 100) % 100); - aReturn.HundredthSeconds = (sal_uInt16)(((sal_uInt32)(_nVal >= 0 ? _nVal : _nVal*-1)) % 100); + sal_uInt64 unVal = static_cast<sal_uInt64>(_nVal >= 0 ? _nVal : -_nVal); + aReturn.Hours = unVal / hourMask; + aReturn.Minutes = (unVal / minMask) % 100; + aReturn.Seconds = (unVal / secMask) % 100; + aReturn.NanoSeconds = unVal % secMask; return aReturn; } - const double fMilliSecondsPerDay = 86400000.0; //------------------------------------------------------------------------------ sal_Int32 DBTypeConversion::toINT32(const Date& rVal) { @@ -122,18 +135,21 @@ namespace dbtools } //------------------------------------------------------------------------------ - sal_Int32 DBTypeConversion::toINT32(const Time& rVal) + sal_Int64 DBTypeConversion::toINT64(const Time& rVal) { // normalize time - sal_Int32 nSeconds = rVal.Seconds + rVal.HundredthSeconds / 100; - sal_Int32 nHundredthSeconds = rVal.HundredthSeconds % 100; - sal_Int32 nMinutes = rVal.Minutes + nSeconds / 60; - nSeconds = nSeconds % 60; - sal_Int32 nHours = rVal.Hours + nMinutes / 60; - nMinutes = nMinutes % 60; + sal_Int32 nSeconds = rVal.Seconds + rVal.NanoSeconds / nanoSecInSec; + sal_Int32 nNanoSeconds = rVal.NanoSeconds % nanoSecInSec; + sal_Int32 nMinutes = rVal.Minutes + nSeconds / secInMin; + nSeconds = nSeconds % secInMin; + sal_Int32 nHours = rVal.Hours + nMinutes / minInHour; + nMinutes = nMinutes % minInHour; // assemble time - return (sal_Int32)(nHundredthSeconds + (nSeconds*100) + (nMinutes*10000) + (nHours*1000000)); + return nNanoSeconds + + nSeconds * secMask + + nMinutes * minMask + + nHours * hourMask; } //------------------------------------------------------------------------------ @@ -142,9 +158,23 @@ namespace dbtools sal_Int32 nHour = rVal.Hours; sal_Int32 nMin = rVal.Minutes; sal_Int32 nSec = rVal.Seconds; - sal_Int32 n100Sec = rVal.HundredthSeconds; + sal_Int32 nNanoSec = rVal.NanoSeconds; - return ((nHour*3600000)+(nMin*60000)+(nSec*1000)+(n100Sec*10)); + return ((nHour*3600000)+(nMin*60000)+(nSec*1000)+(nNanoSec/1000000)); + } + + //------------------------------------------------------------------------------ + sal_Int64 DBTypeConversion::getNsFromTime(const Time& rVal) + { + sal_Int32 nHour = rVal.Hours; + sal_Int32 nMin = rVal.Minutes; + sal_Int32 nSec = rVal.Seconds; + sal_Int32 nNanoSec = rVal.NanoSeconds; + + return nNanoSec + + nSec * nanoSecInSec + + nMin * (secInMin * nanoSecInSec) + + nHour * (minInHour * secInMin * nanoSecInSec); } //------------------------------------------------------------------------------ @@ -195,7 +225,7 @@ namespace dbtools return nDays; } //------------------------------------------------------------------------------ - static void implBuildFromRelative( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_uInt16& rYear) + static void implBuildFromRelative( sal_Int32 nDays, sal_uInt16& rDay, sal_uInt16& rMonth, sal_Int16& rYear) { sal_Int32 nTempDays; sal_Int32 i = 0; @@ -250,7 +280,7 @@ namespace dbtools //------------------------------------------------------------------------------ double DBTypeConversion::toDouble(const Time& rVal) { - return (double)getMsFromTime(rVal) / fMilliSecondsPerDay; + return (double)getNsFromTime(rVal) / fNanoSecondsPerDay; } //------------------------------------------------------------------------------ @@ -262,7 +292,7 @@ namespace dbtools aTimePart.Hours = _rVal.Hours; aTimePart.Minutes = _rVal.Minutes; aTimePart.Seconds = _rVal.Seconds; - aTimePart.HundredthSeconds = _rVal.HundredthSeconds; + aTimePart.NanoSeconds = _rVal.NanoSeconds; return ((double)nTime) + toDouble(aTimePart); } @@ -325,12 +355,12 @@ namespace dbtools Time DBTypeConversion::toTime(double dVal) { sal_Int32 nDays = (sal_Int32)dVal; - sal_Int32 nMS = sal_Int32((dVal - (double)nDays) * fMilliSecondsPerDay + 0.5); + sal_Int32 nNS = sal_Int32((dVal - (double)nDays) * fNanoSecondsPerDay + 0.5); sal_Int16 nSign; - if ( nMS < 0 ) + if ( nNS < 0 ) { - nMS *= -1; + nNS *= -1; nSign = -1; } else @@ -339,24 +369,28 @@ namespace dbtools Time xRet; // normalize time // we have to sal_Int32 here because otherwise we get an overflow - sal_Int32 nHundredthSeconds = nMS/10; - sal_Int32 nSeconds = nHundredthSeconds / 100; - sal_Int32 nMinutes = nSeconds / 60; + sal_Int32 nNanoSeconds = nNS; + sal_Int32 nSeconds = nNanoSeconds / nanoSecInSec; + sal_Int32 nMinutes = nSeconds / secInMin; - xRet.HundredthSeconds = (sal_uInt16)(nHundredthSeconds % 100); - xRet.Seconds = (sal_uInt16)(nSeconds % 60); - xRet.Hours = (sal_uInt16)(nMinutes / 60); - xRet.Minutes = (sal_uInt16)(nMinutes % 60); + xRet.NanoSeconds = nNanoSeconds % nanoSecInSec; + xRet.Seconds = nSeconds % secInMin; + xRet.Hours = nMinutes / minInHour; + xRet.Minutes = nMinutes % minInHour; // assemble time - sal_Int32 nTime = (sal_Int32)(xRet.HundredthSeconds + (xRet.Seconds*100) + (xRet.Minutes*10000) + (xRet.Hours*1000000)) * nSign; + sal_Int64 nTime = nSign * + (xRet.NanoSeconds + + xRet.Seconds * secMask + + xRet.Minutes * minMask + + xRet.Hours * hourMask); if(nTime < 0) { - xRet.HundredthSeconds = 99; - xRet.Minutes = 59; - xRet.Seconds = 59; - xRet.Hours = 23; + xRet.NanoSeconds = nanoSecInSec-1; + xRet.Seconds = secInMin-1; + xRet.Minutes = minInHour-1; + xRet.Hours = 23; } return xRet; } @@ -368,14 +402,14 @@ namespace dbtools DateTime xRet; - xRet.Day = aDate.Day; - xRet.Month = aDate.Month; - xRet.Year = aDate.Year; + xRet.Day = aDate.Day; + xRet.Month = aDate.Month; + xRet.Year = aDate.Year; - xRet.HundredthSeconds = aTime.HundredthSeconds; - xRet.Minutes = aTime.Minutes; - xRet.Seconds = aTime.Seconds; - xRet.Hours = aTime.Hours; + xRet.NanoSeconds = aTime.NanoSeconds; + xRet.Minutes = aTime.Minutes; + xRet.Seconds = aTime.Seconds; + xRet.Hours = aTime.Hours; return xRet; @@ -415,7 +449,8 @@ namespace dbtools if ( -1 != nSeparation ) aTime = toTime( _sSQLString.copy( nSeparation ) ); - return DateTime(aTime.HundredthSeconds,aTime.Seconds,aTime.Minutes,aTime.Hours,aDate.Day,aDate.Month,aDate.Year); + return DateTime(aTime.NanoSeconds, aTime.Seconds, aTime.Minutes, aTime.Hours, + aDate.Day, aDate.Month, aDate.Year); } //----------------------------------------------------------------------------- @@ -426,8 +461,8 @@ namespace dbtools sal_Int32 nIndex = 0; sal_uInt16 nHour = 0, nMinute = 0, - nSecond = 0, - nHundredthSeconds = 0; + nSecond = 0; + sal_uInt32 nNanoSeconds = 0; nHour = (sal_uInt16)_sSQLString.getToken(0,sTimeSep,nIndex).toInt32(); if(nIndex != -1) { @@ -437,17 +472,10 @@ namespace dbtools nSecond = (sal_uInt16)_sSQLString.getToken(0,sTimeSep,nIndex).toInt32(); nIndex = 0; OUString sNano(_sSQLString.getToken(1,'.',nIndex)); - if ( !sNano.isEmpty() ) - { - // our time struct only supports hundredth seconds - sNano = sNano.copy(0,::std::min<sal_Int32>(sNano.getLength(),2)); - const static OUString s_Zeros("00"); - sNano += s_Zeros.copy(0,s_Zeros.getLength() - sNano.getLength()); - nHundredthSeconds = static_cast<sal_uInt16>(sNano.toInt32()); - } + nNanoSeconds = sNano.toInt32(); } } - return Time(nHundredthSeconds,nSecond,nMinute,nHour); + return Time(nNanoSeconds, nSecond, nMinute, nHour); } //......................................................................... diff --git a/connectivity/source/drivers/calc/CTable.cxx b/connectivity/source/drivers/calc/CTable.cxx index 1e37cc38ecc3..b509065cf68c 100644 --- a/connectivity/source/drivers/calc/CTable.cxx +++ b/connectivity/source/drivers/calc/CTable.cxx @@ -370,12 +370,12 @@ static void lcl_SetValue( ORowSetValue& rValue, const Reference<XSpreadsheet>& x { double fCellVal = xCell->getValue(); double fTime = fCellVal - rtl::math::approxFloor( fCellVal ); - long nIntTime = (long)rtl::math::round( fTime * 8640000.0 ); - if ( nIntTime == 8640000 ) - nIntTime = 0; // 23:59:59.995 and above is 00:00:00.00 + sal_Int64 nIntTime = static_cast<sal_Int64>(rtl::math::round( fTime * static_cast<double>(::Time::nanoSecPerDay) )); + if ( nIntTime == ::Time::nanoSecPerDay) + nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 ::com::sun::star::util::Time aTime; - aTime.HundredthSeconds = (sal_uInt16)( nIntTime % 100 ); - nIntTime /= 100; + aTime.NanoSeconds = (sal_uInt32)( nIntTime % ::Time::nanoSecPerSec ); + nIntTime /= ::Time::nanoSecPerSec; aTime.Seconds = (sal_uInt16)( nIntTime % 60 ); nIntTime /= 60; aTime.Minutes = (sal_uInt16)( nIntTime % 60 ); @@ -394,17 +394,17 @@ static void lcl_SetValue( ORowSetValue& rValue, const Reference<XSpreadsheet>& x double fDays = ::rtl::math::approxFloor( fCellVal ); double fTime = fCellVal - fDays; long nIntDays = (long)fDays; - long nIntTime = (long)::rtl::math::round( fTime * 8640000.0 ); - if ( nIntTime == 8640000 ) + sal_Int64 nIntTime = ::rtl::math::round( fTime * static_cast<double>(::Time::nanoSecPerDay) ); + if ( nIntTime == ::Time::nanoSecPerDay ) { - nIntTime = 0; // 23:59:59.995 and above is 00:00:00.00 + nIntTime = 0; // 23:59:59.9999999995 and above is 00:00:00.00 ++nIntDays; // (next day) } ::com::sun::star::util::DateTime aDateTime; - aDateTime.HundredthSeconds = (sal_uInt16)( nIntTime % 100 ); - nIntTime /= 100; + aDateTime.NanoSeconds = (sal_uInt16)( nIntTime % ::Time::nanoSecPerSec ); + nIntTime /= ::Time::nanoSecPerSec; aDateTime.Seconds = (sal_uInt16)( nIntTime % 60 ); nIntTime /= 60; aDateTime.Minutes = (sal_uInt16)( nIntTime % 60 ); diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx index 61f3c8d01e71..7eef298f8f51 100644 --- a/connectivity/source/drivers/dbase/DTable.cxx +++ b/connectivity/source/drivers/dbase/DTable.cxx @@ -108,7 +108,7 @@ void lcl_CalcJulDate(sal_Int32& _nJulianDate,sal_Int32& _nJulianTime,const com:: aDateTime.Month++; } - _nJulianTime = ((aDateTime.Hours*3600000)+(aDateTime.Minutes*60000)+(aDateTime.Seconds*1000)+(aDateTime.HundredthSeconds*10)); + _nJulianTime = ((aDateTime.Hours*3600000)+(aDateTime.Minutes*60000)+(aDateTime.Seconds*1000)+(aDateTime.NanoSeconds/1000000)); /* conversion factors */ sal_uInt16 iy0; sal_uInt16 im0; diff --git a/connectivity/source/drivers/file/FDateFunctions.cxx b/connectivity/source/drivers/file/FDateFunctions.cxx index 03256f7ab7cc..a24c46d5c153 100644 --- a/connectivity/source/drivers/file/FDateFunctions.cxx +++ b/connectivity/source/drivers/file/FDateFunctions.cxx @@ -263,7 +263,7 @@ ORowSetValue OOp_CurTime::operate(const ::std::vector<ORowSetValue>& lhs) const return ORowSetValue(); Time aCurTime( Time::SYSTEM ); - return ::com::sun::star::util::Time(aCurTime.Get100Sec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour()); + return ::com::sun::star::util::Time(aCurTime.GetNanoSec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour()); } //------------------------------------------------------------------ ORowSetValue OOp_Now::operate(const ::std::vector<ORowSetValue>& lhs) const @@ -272,7 +272,7 @@ ORowSetValue OOp_Now::operate(const ::std::vector<ORowSetValue>& lhs) const return ORowSetValue(); DateTime aCurTime( DateTime::SYSTEM ); - return ::com::sun::star::util::DateTime(aCurTime.Get100Sec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour(), + return ::com::sun::star::util::DateTime(aCurTime.GetNanoSec(),aCurTime.GetSec(),aCurTime.GetMin(),aCurTime.GetHour(), aCurTime.GetDay(),aCurTime.GetMonth(),aCurTime.GetYear()); } //------------------------------------------------------------------ diff --git a/connectivity/source/drivers/jdbc/ConnectionLog.cxx b/connectivity/source/drivers/jdbc/ConnectionLog.cxx index 550db58ec1ec..0216ad23186a 100644 --- a/connectivity/source/drivers/jdbc/ConnectionLog.cxx +++ b/connectivity/source/drivers/jdbc/ConnectionLog.cxx @@ -97,8 +97,8 @@ namespace comphelper { namespace log { namespace convert { char buffer[ 30 ]; const size_t buffer_size = sizeof( buffer ); - snprintf( buffer, buffer_size, "%02i:%02i:%02i.%02i", - (int)_rTime.Hours, (int)_rTime.Minutes, (int)_rTime.Seconds, (int)_rTime.HundredthSeconds ); + snprintf( buffer, buffer_size, "%02i:%02i:%02i.%09i", + (int)_rTime.Hours, (int)_rTime.Minutes, (int)_rTime.Seconds, (int)_rTime.NanoSeconds ); return OUString::createFromAscii( buffer ); } @@ -107,9 +107,9 @@ namespace comphelper { namespace log { namespace convert { char buffer[ 30 ]; const size_t buffer_size = sizeof( buffer ); - snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%02i", + snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%09i", (int)_rDateTime.Year, (int)_rDateTime.Month, (int)_rDateTime.Day, - (int)_rDateTime.Hours, (int)_rDateTime.Minutes, (int)_rDateTime.Seconds, (int)_rDateTime.HundredthSeconds ); + (int)_rDateTime.Hours, (int)_rDateTime.Minutes, (int)_rDateTime.Seconds, (int)_rDateTime.NanoSeconds ); return OUString::createFromAscii( buffer ); } diff --git a/connectivity/source/drivers/kab/KResultSet.cxx b/connectivity/source/drivers/kab/KResultSet.cxx index 0ba7e01518c4..faf61bc9a96c 100644 --- a/connectivity/source/drivers/kab/KResultSet.cxx +++ b/connectivity/source/drivers/kab/KResultSet.cxx @@ -344,7 +344,7 @@ DateTime SAL_CALL KabResultSet::getTimestamp(sal_Int32 columnIndex) throw(SQLExc nRet.Hours = nRevision.time().hour(); nRet.Minutes = nRevision.time().minute(); nRet.Seconds = nRevision.time().second(); - nRet.HundredthSeconds = nRevision.time().msec() / 10; + nRet.NanoSeconds = nRevision.time().msec() * ::Time::nanoPerMilli; return nRet; } } diff --git a/connectivity/source/drivers/macab/macabutilities.hxx b/connectivity/source/drivers/macab/macabutilities.hxx index b6afd1cbbe5f..a17bda266458 100644 --- a/connectivity/source/drivers/macab/macabutilities.hxx +++ b/connectivity/source/drivers/macab/macabutilities.hxx @@ -92,7 +92,7 @@ namespace connectivity nRet.Hours = ptm->tm_hour; nRet.Minutes = ptm->tm_min; nRet.Seconds = ptm->tm_sec; - nRet.HundredthSeconds = 0; + nRet.NanoSeconds = 0; return nRet; } diff --git a/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx index 4e5a11350221..fec060d556c1 100644 --- a/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx +++ b/connectivity/source/drivers/odbcbase/ODatabaseMetaDataResultSet.cxx @@ -436,7 +436,7 @@ OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP,m_bWasNull,**this,&aTime,sizeof aTime); else m_bWasNull = sal_True; - return DateTime((sal_uInt16)aTime.fraction/ODBC_FRACTION_UNITS_PER_HSECOND,aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year); + return DateTime(aTime.fraction,aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year); } // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx b/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx index 9cca1903fe17..5d234c445ea4 100644 --- a/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx +++ b/connectivity/source/drivers/odbcbase/OPreparedStatement.cxx @@ -411,14 +411,27 @@ void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& aVal ) throw(SQLException, RuntimeException) { - const sal_uInt16 hundredths (aVal.HundredthSeconds); SQLULEN nColSize; - if(hundredths == 0) + if(aVal.NanoSeconds == 0) nColSize = 8; - else if(hundredths % 10 == 0) + else if(aVal.NanoSeconds % 100000000 == 0) nColSize = 10; - else + else if(aVal.NanoSeconds % 10000000 == 0) nColSize = 11; + else if(aVal.NanoSeconds % 1000000 == 0) + nColSize = 12; + else if(aVal.NanoSeconds % 100000 == 0) + nColSize = 13; + else if(aVal.NanoSeconds % 10000 == 0) + nColSize = 14; + else if(aVal.NanoSeconds % 1000 == 0) + nColSize = 15; + else if(aVal.NanoSeconds % 100 == 0) + nColSize = 16; + else if(aVal.NanoSeconds % 10 == 0) + nColSize = 17; + else + nColSize = 18; TIME_STRUCT x(OTools::TimeToOdbcTime(aVal)); setScalarParameter<TIME_STRUCT&>(parameterIndex, DataType::TIME, nColSize, x); } @@ -426,20 +439,32 @@ void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& aVal ) throw(SQLException, RuntimeException) { - sal_uInt16 s(aVal.Seconds); - sal_uInt16 hundredths(aVal.HundredthSeconds); SQLULEN nColSize; - if(hundredths == 0) + if(aVal.NanoSeconds == 0) { - if (s == 0) + if (aVal.Seconds == 0) nColSize=16; else nColSize=19; } - else if(hundredths % 10 == 0) + else if(aVal.NanoSeconds % 100000000 == 0) nColSize = 21; - else + else if(aVal.NanoSeconds % 10000000 == 0) nColSize = 22; + else if(aVal.NanoSeconds % 1000000 == 0) + nColSize = 23; + else if(aVal.NanoSeconds % 100000 == 0) + nColSize = 24; + else if(aVal.NanoSeconds % 10000 == 0) + nColSize = 25; + else if(aVal.NanoSeconds % 1000 == 0) + nColSize = 26; + else if(aVal.NanoSeconds % 100 == 0) + nColSize = 27; + else if(aVal.NanoSeconds % 10 == 0) + nColSize = 28; + else + nColSize = 29; TIMESTAMP_STRUCT x(OTools::DateTimeToTimestamp(aVal)); setScalarParameter<TIMESTAMP_STRUCT&>(parameterIndex, DataType::TIMESTAMP, nColSize, x); diff --git a/connectivity/source/drivers/odbcbase/OResultSet.cxx b/connectivity/source/drivers/odbcbase/OResultSet.cxx index dcc7c88909b5..211ba70703ee 100644 --- a/connectivity/source/drivers/odbcbase/OResultSet.cxx +++ b/connectivity/source/drivers/odbcbase/OResultSet.cxx @@ -663,7 +663,7 @@ DateTime OResultSet::impl_getTimestamp( sal_Int32 columnIndex ) throw(SQLExcepti TIMESTAMP_STRUCT aTime = impl_getValue< TIMESTAMP_STRUCT > ( columnIndex, m_pStatement->getOwnConnection()->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP ); - return DateTime(static_cast<sal_uInt16>(aTime.fraction/ODBC_FRACTION_UNITS_PER_HSECOND), + return DateTime(aTime.fraction, aTime.second, aTime.minute, aTime.hour, diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx index ccce76f018c1..a9be424d9b34 100644 --- a/connectivity/source/drivers/postgresql/pq_tools.cxx +++ b/connectivity/source/drivers/postgresql/pq_tools.cxx @@ -107,6 +107,7 @@ namespace pq_sdbc_driver OUString date2String( const com::sun::star::util::Date & x ) { + // TODO FIXME: replace by DBTypeConversion::toDateString char buffer[64]; sprintf( buffer, "%d-%02d-%02d", x.Year, x.Month, x.Day ); return OUString::createFromAscii( buffer ); @@ -114,6 +115,7 @@ OUString date2String( const com::sun::star::util::Date & x ) com::sun::star::util::Date string2Date( const OUString &date ) { + // TODO FIXME: replace by DBTypeConversion::toDate (if it parses the same format) // Format: Year-Month-Day com::sun::star::util::Date ret; @@ -135,15 +137,17 @@ com::sun::star::util::Date string2Date( const OUString &date ) OUString time2String( const com::sun::star::util::Time & x ) { - char buffer[64]; - sprintf( buffer, "%02d:%02d:%02d.%02d", x.Hours, x.Minutes, x.Seconds, x.HundredthSeconds ); + // TODO FIXME: replace by DBTypeConversion::toTimeString + const size_t buflen = 19; + char buffer[buflen]; + snprintf( buffer, buflen, "%02d:%02d:%02d.%09d", x.Hours, x.Minutes, x.Seconds, x.NanoSeconds ); return OUString::createFromAscii( buffer ); - } com::sun::star::util::Time string2Time( const OUString & time ) { + // TODO FIXME: replace by DBTypeConversion::toTime com::sun::star::util::Time ret; sal_Unicode temp[4]; @@ -163,7 +167,8 @@ com::sun::star::util::Time string2Time( const OUString & time ) if( time.getLength() >9 ) { - ret.HundredthSeconds = (sal_Int32)rtl_ustr_toInt32( &time.getStr()[9] , 10 ); + // FIXME does not take into account shorter precision + ret.NanoSeconds = (sal_Int32)rtl_ustr_toInt32( &time.getStr()[9] , 10 ); } return ret; @@ -173,16 +178,18 @@ com::sun::star::util::Time string2Time( const OUString & time ) OUString dateTime2String( const com::sun::star::util::DateTime & x ) { + // TODO FIXME: replace by DBTypeConversion::toDateTimeString char buffer[128]; - sprintf( buffer, "%d-%02d-%02d %02d:%02d:%02d.%02d", + sprintf( buffer, "%d-%02d-%02d %02d:%02d:%02d.%09d", x.Year, x.Month, x.Day, - x.Hours, x.Minutes, x.Seconds, x.HundredthSeconds ); + x.Hours, x.Minutes, x.Seconds, x.NanoSeconds ); return OUString::createFromAscii( buffer ); } com::sun::star::util::DateTime string2DateTime( const OUString & dateTime ) { + // TODO FIXME: replace by DBTypeConversion::toDateTime (if same format) int space = dateTime.indexOf( ' ' ); com::sun::star::util::DateTime ret; @@ -197,7 +204,7 @@ com::sun::star::util::DateTime string2DateTime( const OUString & dateTime ) ret.Hours = time.Hours; ret.Minutes = time.Minutes; ret.Seconds = time.Seconds; - ret.HundredthSeconds = time.HundredthSeconds; + ret.NanoSeconds = time.NanoSeconds; } return ret; } diff --git a/connectivity/source/inc/odbc/OTools.hxx b/connectivity/source/inc/odbc/OTools.hxx index 79be84caf0d2..015e5f2a13ec 100644 --- a/connectivity/source/inc/odbc/OTools.hxx +++ b/connectivity/source/inc/odbc/OTools.hxx @@ -91,7 +91,6 @@ namespace connectivity { class OConnection; - const sal_uInt32 ODBC_FRACTION_UNITS_PER_HSECOND = 10000000L; const sal_Int32 MAX_PUT_DATA_LENGTH = 2000; class OOO_DLLPUBLIC_ODBCBASE OTools @@ -166,7 +165,7 @@ namespace connectivity aVal.hour = x.Hours; aVal.minute = x.Minutes; aVal.second = x.Seconds; - aVal.fraction = x.HundredthSeconds * ODBC_FRACTION_UNITS_PER_HSECOND; + aVal.fraction = x.NanoSeconds; return aVal; } /** diff --git a/editeng/source/items/flditem.cxx b/editeng/source/items/flditem.cxx index 0f4e2aeab093..bc67903341eb 100644 --- a/editeng/source/items/flditem.cxx +++ b/editeng/source/items/flditem.cxx @@ -85,7 +85,7 @@ SvxFieldData* SvxFieldData::Create(const uno::Reference<text::XTextContent>& xTe if (nFieldType != text::textfield::Type::TIME && nFieldType != text::textfield::Type::DATE) { util::DateTime aDateTime = xPropSet->getPropertyValue(UNO_TC_PROP_DATE_TIME).get<util::DateTime>(); - Time aTime(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds); + Time aTime(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.NanoSeconds); sal_Bool bIsFixed = false; xPropSet->getPropertyValue(UNO_TC_PROP_IS_FIXED) >>= bIsFixed; diff --git a/editeng/source/uno/unofield.cxx b/editeng/source/uno/unofield.cxx index 9aa5b0b2b334..86a039b89f47 100644 --- a/editeng/source/uno/unofield.cxx +++ b/editeng/source/uno/unofield.cxx @@ -208,7 +208,7 @@ static util::DateTime getTime( long nTime ) Time aTempTime( nTime ); - aTime.HundredthSeconds = aTempTime.Get100Sec(); + aTime.NanoSeconds = aTempTime.GetNanoSec(); aTime.Seconds = aTempTime.GetSec(); aTime.Minutes = aTempTime.GetMin(); aTime.Hours = aTempTime.GetHour(); @@ -218,7 +218,7 @@ static util::DateTime getTime( long nTime ) inline Time setTime( util::DateTime& rDate ) { - return Time( rDate.Hours, rDate.Minutes, rDate.Seconds, rDate.HundredthSeconds ); + return Time( rDate.Hours, rDate.Minutes, rDate.Seconds, rDate.NanoSeconds ); } // ==================================================================== diff --git a/extensions/source/logging/csvformatter.cxx b/extensions/source/logging/csvformatter.cxx index 19b2a2b2b692..7bf518813c33 100644 --- a/extensions/source/logging/csvformatter.cxx +++ b/extensions/source/logging/csvformatter.cxx @@ -263,14 +263,14 @@ namespace logging // ISO 8601 char buffer[ 30 ]; const size_t buffer_size = sizeof( buffer ); - snprintf( buffer, buffer_size, "%04i-%02i-%02iT%02i:%02i:%02i.%02i", + snprintf( buffer, buffer_size, "%04i-%02i-%02iT%02i:%02i:%02i.%09i", (int)record.LogTime.Year, (int)record.LogTime.Month, (int)record.LogTime.Day, (int)record.LogTime.Hours, (int)record.LogTime.Minutes, (int)record.LogTime.Seconds, - (int)record.LogTime.HundredthSeconds ); + (int)record.LogTime.NanoSeconds ); aLogEntry.appendAscii( buffer ); aLogEntry.append(comma_char); } diff --git a/extensions/source/logging/logrecord.cxx b/extensions/source/logging/logrecord.cxx index ce9c8ba8d036..dfd0cb8f21d1 100644 --- a/extensions/source/logging/logrecord.cxx +++ b/extensions/source/logging/logrecord.cxx @@ -68,7 +68,7 @@ namespace logging aTimeStamp.Hours = aDateTime.Hours; aTimeStamp.Minutes = aDateTime.Minutes; aTimeStamp.Seconds = aDateTime.Seconds; - aTimeStamp.HundredthSeconds = ::sal::static_int_cast< sal_Int16 >( aDateTime.NanoSeconds / 10000000 ); + aTimeStamp.NanoSeconds = aDateTime.NanoSeconds; return LogRecord( _rLoggerName, diff --git a/extensions/source/logging/plaintextformatter.cxx b/extensions/source/logging/plaintextformatter.cxx index 7396263b8a24..7ce48752cc85 100644 --- a/extensions/source/logging/plaintextformatter.cxx +++ b/extensions/source/logging/plaintextformatter.cxx @@ -129,9 +129,9 @@ namespace logging aLogEntry.appendAscii( buffer ); aLogEntry.appendAscii( " " ); - snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%02i", + snprintf( buffer, buffer_size, "%04i-%02i-%02i %02i:%02i:%02i.%09i", (int)_rRecord.LogTime.Year, (int)_rRecord.LogTime.Month, (int)_rRecord.LogTime.Day, - (int)_rRecord.LogTime.Hours, (int)_rRecord.LogTime.Minutes, (int)_rRecord.LogTime.Seconds, (int)_rRecord.LogTime.HundredthSeconds ); + (int)_rRecord.LogTime.Hours, (int)_rRecord.LogTime.Minutes, (int)_rRecord.LogTime.Seconds, (int)_rRecord.LogTime.NanoSeconds ); aLogEntry.appendAscii( buffer ); aLogEntry.appendAscii( " " ); diff --git a/extensions/source/propctrlr/formcomponenthandler.cxx b/extensions/source/propctrlr/formcomponenthandler.cxx index 2b68425ae3af..773a4e6e199d 100644 --- a/extensions/source/propctrlr/formcomponenthandler.cxx +++ b/extensions/source/propctrlr/formcomponenthandler.cxx @@ -590,7 +590,7 @@ namespace pcr { util::Time aTime; OSL_VERIFY( _rControlValue >>= aTime ); - aPropertyValue <<= (sal_Int32)DBTypeConversion::toINT32( aTime ); + aPropertyValue <<= DBTypeConversion::toINT64( aTime ); } break; @@ -726,7 +726,7 @@ namespace pcr case PROPERTY_ID_DEFAULT_TIME: case PROPERTY_ID_TIME: { - sal_Int32 nTime = 0; + sal_Int64 nTime = 0; OSL_VERIFY( _rPropertyValue >>= nTime ); aControlValue <<= DBTypeConversion::toTime( nTime ); } diff --git a/extensions/source/propctrlr/standardcontrol.cxx b/extensions/source/propctrlr/standardcontrol.cxx index f9caaae10131..60f533ac9df1 100644 --- a/extensions/source/propctrlr/standardcontrol.cxx +++ b/extensions/source/propctrlr/standardcontrol.cxx @@ -87,7 +87,7 @@ namespace pcr } else { - ::Time aTime( aUNOTime.Hours, aUNOTime.Minutes, aUNOTime.Seconds, aUNOTime.HundredthSeconds ); + ::Time aTime( aUNOTime.Hours, aUNOTime.Minutes, aUNOTime.Seconds, aUNOTime.NanoSeconds ); getTypedControlWindow()->SetTime( aTime ); } } @@ -99,7 +99,7 @@ namespace pcr if ( !getTypedControlWindow()->GetText().isEmpty() ) { ::Time aTime( getTypedControlWindow()->GetTime() ); - util::Time aUNOTime( aTime.Get100Sec(), aTime.GetSec(), aTime.GetMin(), aTime.GetHour() ); + util::Time aUNOTime( aTime.GetNanoSec(), aTime.GetSec(), aTime.GetMin(), aTime.GetHour() ); aPropValue <<= aUNOTime; } return aPropValue; diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx index 104db58723a7..b8b680bfe67a 100644 --- a/filter/source/msfilter/svdfppt.cxx +++ b/filter/source/msfilter/svdfppt.cxx @@ -118,6 +118,7 @@ #include <algorithm> #include <set> #include <rtl/strbuf.hxx> +#include <tools/time.hxx> // PPT ColorScheme Slots #define PPT_COLSCHEME (0x08000000) @@ -2673,11 +2674,11 @@ void ImportComment10( SvxMSDffManager& rMan, SvStream& rStCtrl, SdrPage* pPage, >> aDateTime.Hours >> aDateTime.Minutes >> aDateTime.Seconds - >> aDateTime.HundredthSeconds + >> aDateTime.NanoSeconds >> nPosX >> nPosY; - aDateTime.HundredthSeconds /= 10; + aDateTime.NanoSeconds *= ::Time::nanoPerMilli; } break; } diff --git a/forms/qa/integration/forms/TimeValidator.java b/forms/qa/integration/forms/TimeValidator.java index ab9f036c2b67..36d1ae8f6e90 100644 --- a/forms/qa/integration/forms/TimeValidator.java +++ b/forms/qa/integration/forms/TimeValidator.java @@ -70,11 +70,11 @@ public class TimeValidator extends integration.forms.ControlValidator private boolean isInvalidTime( com.sun.star.util.Time timeValue ) { - return ( timeValue.Hours == -1 ) && ( timeValue.Minutes == -1 ) && ( timeValue.Seconds == -1 ) && ( timeValue.HundredthSeconds == -1 ); + return ( timeValue.Hours == -1 ) && ( timeValue.Minutes == -1 ) && ( timeValue.Seconds == -1 ) && ( timeValue.NanoSeconds == -1 ); } private boolean isFullHour( com.sun.star.util.Time timeValue ) { - return ( timeValue.Minutes == 0 ) && ( timeValue.Seconds == 0 ) && ( timeValue.HundredthSeconds == 0 ); + return ( timeValue.Minutes == 0 ) && ( timeValue.Seconds == 0 ) && ( timeValue.NanoSeconds == 0 ); } } diff --git a/forms/source/component/Time.cxx b/forms/source/component/Time.cxx index 7b7b56c2821c..420a317fcefd 100644 --- a/forms/source/component/Time.cxx +++ b/forms/source/component/Time.cxx @@ -246,7 +246,7 @@ sal_Bool OTimeModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) util::Time aTime; if ( !( aControlValue >>= aTime ) ) { - sal_Int32 nAsInt(0); + sal_Int64 nAsInt(0); aControlValue >>= nAsInt; aTime = DBTypeConversion::toTime(nAsInt); } @@ -256,7 +256,7 @@ sal_Bool OTimeModel::commitControlValueToDbColumn( bool /*_bPostReset*/ ) else { util::DateTime aDateTime = m_xColumn->getTimestamp(); - aDateTime.HundredthSeconds = aTime.HundredthSeconds; + aDateTime.NanoSeconds = aTime.NanoSeconds; aDateTime.Seconds = aTime.Seconds; aDateTime.Minutes = aTime.Minutes; aDateTime.Hours = aTime.Hours; @@ -279,7 +279,7 @@ void OTimeModel::impl_translateControlValueToUNOTime( Any& _rUNOValue ) const _rUNOValue = getControlValue(); if ( _rUNOValue.hasValue() ) { - sal_Int32 nTime = 0; + sal_Int64 nTime = 0; OSL_VERIFY( _rUNOValue >>= nTime ); if ( nTime == ::Time( 99, 99, 99 ).GetTime() ) // "invalid time" in VCL is different from "invalid time" in UNO @@ -305,7 +305,7 @@ Any OTimeModel::translateExternalValueToControlValue( const Any& _rExternalValue { util::Time aTime; OSL_VERIFY( _rExternalValue >>= aTime ); - aControlValue <<= DBTypeConversion::toINT32( aTime ); + aControlValue <<= DBTypeConversion::toINT64( aTime ); } return aControlValue; } @@ -325,8 +325,9 @@ Any OTimeModel::translateDbColumnToControlValue() if ( m_xColumn->wasNull() ) m_aSaveValue.clear(); else - // the aggregated set expects an Int32 as value ... - m_aSaveValue <<= DBTypeConversion::toINT32( aTime ); + // TODO FIXME: "the aggregated set expects an Int32 as value ..." + // need to fix it for int64 + m_aSaveValue <<= DBTypeConversion::toINT64( aTime ); return m_aSaveValue; } diff --git a/forms/source/xforms/convert.cxx b/forms/source/xforms/convert.cxx index b440f4b3705f..6dac9298aa6a 100644 --- a/forms/source/xforms/convert.cxx +++ b/forms/source/xforms/convert.cxx @@ -33,13 +33,14 @@ #include <com/sun/star/util/Date.hpp> #include <com/sun/star/util/DateTime.hpp> #include <com/sun/star/util/Time.hpp> +#include <unotools/datetime.hxx> using xforms::Convert; using com::sun::star::uno::Any; using com::sun::star::uno::makeAny; -using com::sun::star::util::Time; using namespace std; using namespace o3tl; +using namespace utl; typedef com::sun::star::util::Date UNODate; typedef com::sun::star::util::Time UNOTime; @@ -279,30 +280,7 @@ namespace UNODate aDate( 1, 1, 1900 ); - sal_Int32 nToken = 0; - StringTokenizer aTokenizer( rString, '-' ); - while ( aTokenizer.hasNextToken() ) - { - sal_Int32 nTokenValue = 0; - if ( !aTokenizer.getNextToken().toInt32( nTokenValue ) ) - { - bWellformed = false; - break; - } - - if ( nToken == 0 ) - aDate.Year = (sal_uInt16)nTokenValue; - else if ( nToken == 1 ) - aDate.Month = (sal_uInt16)nTokenValue; - else if ( nToken == 2 ) - aDate.Day = (sal_uInt16)nTokenValue; - else - { - bWellformed = false; - break; - } - ++nToken; - } + bWellformed = ISO8601parseDate(rString, aDate); // sanity checks if ( ( aDate.Year > 9999 ) || ( aDate.Month < 1 ) || ( aDate.Month > 12 ) || ( aDate.Day < 1 ) || ( aDate.Day > 31 ) ) @@ -337,10 +315,15 @@ namespace lcl_appendInt32ToBuffer( rTime.Minutes, sInfo, 2 ); sInfo.appendAscii( ":" ); lcl_appendInt32ToBuffer( rTime.Seconds, sInfo, 2 ); - if ( rTime.HundredthSeconds ) + if ( rTime.NanoSeconds != 0 ) { - sInfo.appendAscii( "." ); - lcl_appendInt32ToBuffer( rTime.HundredthSeconds, sInfo, 2 ); + OSL_ENSURE(rTime.NanoSeconds < 1000000000,"NanoSeconds cannot be more than 999 999 999"); + sInfo.append('.'); + std::ostringstream ostr; + ostr.fill('0'); + ostr.width(9); + ostr << rTime.NanoSeconds; + sInfo.append(OUString::createFromAscii(ostr.str().c_str())); } return sInfo.makeStringAndClear(); @@ -361,62 +344,7 @@ namespace UNOTime aTime( 0, 0, 0, 0 ); - OUString sString( rString ); - // see if there's a decimal separator for the seconds, - // and if so, handle it separately - sal_Int32 nDecimalSepPos = rString.indexOf( '.' ); - if ( nDecimalSepPos == -1 ) - // ISO 8601 allows for both a comma and a dot - nDecimalSepPos = rString.indexOf( ',' ); - if ( nDecimalSepPos != -1 ) - { - // handle fractional seconds - OUString sFractional = sString.copy( nDecimalSepPos + 1 ); - if ( sFractional.getLength() > 2 ) - // our precision is HundrethSeconds - it's all a css.util.Time can hold - sFractional = sFractional.copy( 0, 2 ); - if ( !sFractional.isEmpty() ) - { - sal_Int32 nFractional = 0; - if ( StringTokenizer( sFractional, 0 ).getNextToken().toInt32( nFractional ) ) - { - aTime.HundredthSeconds = (sal_uInt16)nFractional; - if ( nFractional < 10 ) - aTime.HundredthSeconds *= 10; - } - else - bWellformed = false; - } - - // strip the fraction before further processing - sString = sString.copy( 0, nDecimalSepPos ); - } - - // split into the tokens which are separated by colon - sal_Int32 nToken = 0; - StringTokenizer aTokenizer( sString, ':' ); - while ( aTokenizer.hasNextToken() ) - { - sal_Int32 nTokenValue = 0; - if ( !aTokenizer.getNextToken().toInt32( nTokenValue ) ) - { - bWellformed = false; - break; - } - - if ( nToken == 0 ) - aTime.Hours = (sal_uInt16)nTokenValue; - else if ( nToken == 1 ) - aTime.Minutes = (sal_uInt16)nTokenValue; - else if ( nToken == 2 ) - aTime.Seconds = (sal_uInt16)nTokenValue; - else - { - bWellformed = false; - break; - } - ++nToken; - } + bWellformed = ISO8601parseTime(rString, aTime); // sanity checks // note that Seconds == 60 denotes leap seconds. Normally, they're not allowed everywhere, @@ -431,7 +359,7 @@ namespace && ( aTime.Hours == 24 ) && ( ( aTime.Minutes != 0 ) || ( aTime.Seconds != 0 ) - || ( aTime.HundredthSeconds != 0 ) + || ( aTime.NanoSeconds != 0 ) ) ) bWellformed = false; @@ -458,7 +386,7 @@ namespace UNODate aDate( aDateTime.Day, aDateTime.Month, aDateTime.Year ); OUString sDate = lcl_toXSD_UNODate_typed( aDate ); - UNOTime aTime( aDateTime.HundredthSeconds, aDateTime.Seconds, aDateTime.Minutes, aDateTime.Hours ); + UNOTime aTime( aDateTime.NanoSeconds, aDateTime.Seconds, aDateTime.Minutes, aDateTime.Hours ); OUString sTime = lcl_toXSD_UNOTime_typed( aTime ); OUStringBuffer sInfo; @@ -489,7 +417,7 @@ namespace aTime = lcl_toUNOTime( rString.copy( nDateTimeSep + 1 ) ); } UNODateTime aDateTime( - aTime.HundredthSeconds, aTime.Seconds, aTime.Minutes, aTime.Hours, + aTime.NanoSeconds, aTime.Seconds, aTime.Minutes, aTime.Hours, aDate.Day, aDate.Month, aDate.Year ); return makeAny( aDateTime ); diff --git a/forms/source/xforms/datatypes.cxx b/forms/source/xforms/datatypes.cxx index e1fcdebecf24..66dbd907856a 100644 --- a/forms/source/xforms/datatypes.cxx +++ b/forms/source/xforms/datatypes.cxx @@ -829,7 +829,14 @@ namespace xforms if ( !( aTypedValue >>= aValue ) ) return false; - ::Time aToolsTime( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.HundredthSeconds ); + ::Time aToolsTime( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.NanoSeconds ); + // no loss/rounding; IEEE 754 double-precision floating-point + // has a mantissa of 53 bits; we need at the very most 50 bits: + // format of aToolsTime.GetTime() is (in decimal) hhmmssnnnnnnnnn + // and 999999999999999 = 0x38D7EA4C67FFF + // in reality I doubt we need (much) more than + // 240000000000000 = 0x0DA475ABF0000 + // that is 48 bits fValue = aToolsTime.GetTime(); return true; } @@ -846,7 +853,7 @@ namespace xforms { Time aValue; OSL_VERIFY( _rValue >>= aValue ); - ::Time aToolsTime( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.HundredthSeconds ); + ::Time aToolsTime( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.NanoSeconds ); _rDoubleValue = aToolsTime.GetTime(); } @@ -869,7 +876,7 @@ namespace xforms { ::DateTime aToolsValue( ::Date( _rValue.Day, _rValue.Month, _rValue.Year ), - ::Time( _rValue.Hours, _rValue.Minutes, _rValue.Seconds, _rValue.HundredthSeconds ) + ::Time( _rValue.Hours, _rValue.Minutes, _rValue.Seconds, _rValue.NanoSeconds ) ); double fValue = 0; diff --git a/framework/source/jobs/jobdata.cxx b/framework/source/jobs/jobdata.cxx index a39114d82a7c..051fd7a5d093 100644 --- a/framework/source/jobs/jobdata.cxx +++ b/framework/source/jobs/jobdata.cxx @@ -567,6 +567,7 @@ sal_Bool isEnabled( const OUString& sAdminTime , // We check for "isEnabled()" here only. // Note further: ISO8601 formated strings can be compared as strings directly! + // FIXME: this is not true! "T1215" is the same time as "T12:15" or "T121500" return ( (!bValidAdmin && !bValidUser ) || ( bValidAdmin && bValidUser && sAdminTime>=sUserTime) diff --git a/odk/examples/DevelopersGuide/Forms/TimeValidator.java b/odk/examples/DevelopersGuide/Forms/TimeValidator.java index 81042294441a..333e7c95dc5e 100644 --- a/odk/examples/DevelopersGuide/Forms/TimeValidator.java +++ b/odk/examples/DevelopersGuide/Forms/TimeValidator.java @@ -70,11 +70,11 @@ public class TimeValidator extends ControlValidator private boolean isInvalidTime( com.sun.star.util.Time timeValue ) { - return ( timeValue.Hours == -1 ) && ( timeValue.Minutes == -1 ) && ( timeValue.Seconds == -1 ) && ( timeValue.HundredthSeconds == -1 ); + return ( timeValue.Hours == -1 ) && ( timeValue.Minutes == -1 ) && ( timeValue.Seconds == -1 ) && ( timeValue.NanoSeconds == -1 ); } private boolean isFullHour( com.sun.star.util.Time timeValue ) { - return ( timeValue.Minutes == 0 ) && ( timeValue.Seconds == 0 ) && ( timeValue.HundredthSeconds == 0 ); + return ( timeValue.Minutes == 0 ) && ( timeValue.Seconds == 0 ) && ( timeValue.NanoSeconds == 0 ); } } diff --git a/offapi/com/sun/star/util/Date.idl b/offapi/com/sun/star/util/Date.idl index d881fd4077b4..ecbda5a8b307 100644 --- a/offapi/com/sun/star/util/Date.idl +++ b/offapi/com/sun/star/util/Date.idl @@ -40,7 +40,7 @@ published struct Date /** contains the year. */ - unsigned short Year; + short Year; }; diff --git a/offapi/com/sun/star/util/DateTime.idl b/offapi/com/sun/star/util/DateTime.idl index 11f672ba1f5f..312589f9eb73 100644 --- a/offapi/com/sun/star/util/DateTime.idl +++ b/offapi/com/sun/star/util/DateTime.idl @@ -28,10 +28,9 @@ module com { module sun { module star { module util { */ published struct DateTime { - /** contains the hundredth seconds (0-99). + /** contains the nanoseconds (0 - 999 999 999). */ - unsigned short HundredthSeconds; - + unsigned long NanoSeconds; /** contains the seconds (0-59). */ @@ -60,7 +59,9 @@ published struct DateTime /** is the year. */ - unsigned short Year; + short Year; + + /** TODO: timezone **/ }; diff --git a/offapi/com/sun/star/util/DateTimeRange.idl b/offapi/com/sun/star/util/DateTimeRange.idl index 94e005a37c59..b56a0484e494 100644 --- a/offapi/com/sun/star/util/DateTimeRange.idl +++ b/offapi/com/sun/star/util/DateTimeRange.idl @@ -28,9 +28,9 @@ module com { module sun { module star { module util { */ published struct DateTimeRange { - /** contains the start hundredth seconds (0-99) for the range. + /** contains the start nanoseconds (0 - 999 999 999) for the range. */ - unsigned short StartHundredthSeconds; + unsigned long StartNanoSeconds; /** contains the start seconds (0-59) for the range. */ @@ -54,11 +54,11 @@ published struct DateTimeRange /** contains the start year for the range. */ - unsigned short StartYear; + short StartYear; - /** contains the end hundredth seconds (0-99) for the range. + /** contains the end nanoseconds (0 - 999 999 999) for the range. */ - unsigned short EndHundredthSeconds; + unsigned long EndNanoSeconds; /** contains the end seconds (0-59) for the range. */ @@ -82,8 +82,9 @@ published struct DateTimeRange /** contains the end year for the range. */ - unsigned short EndYear; + short EndYear; + /** TODO timezones **/ }; diff --git a/offapi/com/sun/star/util/Duration.idl b/offapi/com/sun/star/util/Duration.idl index 6b373ddb853c..519e837fef1a 100644 --- a/offapi/com/sun/star/util/Duration.idl +++ b/offapi/com/sun/star/util/Duration.idl @@ -69,9 +69,9 @@ struct Duration */ unsigned short Seconds; - /** contains the milliseconds. + /** contains the nanoseconds. */ - unsigned short MilliSeconds; + unsigned long NanoSeconds; }; diff --git a/offapi/com/sun/star/util/Time.idl b/offapi/com/sun/star/util/Time.idl index 51cbd7e6c197..1ac850f31797 100644 --- a/offapi/com/sun/star/util/Time.idl +++ b/offapi/com/sun/star/util/Time.idl @@ -28,9 +28,9 @@ module com { module sun { module star { module util { */ published struct Time { - /** contains the hundredth seconds (0-99). + /** contains the nanoseconds (0 - 999 999 999). */ - unsigned short HundredthSeconds; + unsigned long NanoSeconds; /** contains the seconds (0-59). */ diff --git a/offapi/type_reference/types.rdb b/offapi/type_reference/types.rdb Binary files differindex f43806a7a4f3..ecd1b60cac58 100644 --- a/offapi/type_reference/types.rdb +++ b/offapi/type_reference/types.rdb diff --git a/oox/source/core/xmlfilterbase.cxx b/oox/source/core/xmlfilterbase.cxx index 73d223eec1bc..28d47c2374c2 100644 --- a/oox/source/core/xmlfilterbase.cxx +++ b/oox/source/core/xmlfilterbase.cxx @@ -482,10 +482,12 @@ writeElement( FSHelperPtr pDoc, sal_Int32 nXmlElement, const util::DateTime& rTi FSEND ); char pStr[200]; - snprintf( pStr, sizeof( pStr ), "%d-%02d-%02dT%02d:%02d:%02d.%02dZ", + // FIXME: my guess is that precision greater than millisecond in undesirable + // (forbidden by the standard???) + snprintf( pStr, sizeof( pStr ), "%d-%02d-%02dT%02d:%02d:%02d.%09dZ", rTime.Year, rTime.Month, rTime.Day, rTime.Hours, rTime.Minutes, rTime.Seconds, - rTime.HundredthSeconds ); + rTime.NanoSeconds); pDoc->write( pStr ); diff --git a/oox/source/dump/dumperbase.cxx b/oox/source/dump/dumperbase.cxx index dfa19ba4c013..867a66f1f4e3 100644 --- a/oox/source/dump/dumperbase.cxx +++ b/oox/source/dump/dumperbase.cxx @@ -2285,11 +2285,11 @@ util::DateTime InputObjectBase::dumpFileTime( const String& rName ) } // the day aDateTime.Day = static_cast< sal_uInt16 >( nDaysInYear + 1 ); - // number of 1/100 seconds in the day - sal_Int64 nTimeInDay = nFileTime % sal_Int64( 360000 * 24 ); - // 1/100 seconds - aDateTime.HundredthSeconds = static_cast< sal_uInt16 >( nTimeInDay % 100 ); - nTimeInDay /= 100; + // number of nanoseconds in the day + sal_Int64 nTimeInDay = nFileTime % sal_Int64( 86400000000000 ); + // nanoseconds + aDateTime.NanoSeconds = static_cast< sal_uInt32 >( nTimeInDay % 1000000000 ); + nTimeInDay /= 1000000000; // seconds aDateTime.Seconds = static_cast< sal_uInt16 >( nTimeInDay % 60 ); nTimeInDay /= 60; diff --git a/oox/source/ppt/comments.cxx b/oox/source/ppt/comments.cxx index 26725ffdf0f6..bf598c7e3386 100644 --- a/oox/source/ppt/comments.cxx +++ b/oox/source/ppt/comments.cxx @@ -9,6 +9,7 @@ #include "oox/ppt/comments.hxx" #include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <rtl/math.hxx> namespace oox { namespace ppt { @@ -37,7 +38,28 @@ void Comment::setDateTime (OUString datetime) datetime = datetime.getToken(1,'T'); aDateTime.Hours = datetime.getToken(0,':').toInt32(); aDateTime.Minutes = datetime.getToken(1,':').toInt32(); - aDateTime.HundredthSeconds = int(datetime.getToken(2,':').toDouble() + .5); + double seconds = datetime.getToken(2,':').toDouble(); + aDateTime.Seconds = floor(seconds); + seconds -= aDateTime.Seconds; + aDateTime.NanoSeconds = ::rtl::math::round(seconds * 1000000000); + const int secondsOverFlow = (aDateTime.Seconds == 60) ? 61 : 60; + // normalise time part of aDateTime + if (aDateTime.NanoSeconds == 1000000000) + { + aDateTime.NanoSeconds = 0; + ++aDateTime.Seconds; + } + if (aDateTime.Seconds == secondsOverFlow) + { + aDateTime.Seconds = 0; + ++aDateTime.Minutes; + } + if (aDateTime.Minutes == 60) + { + aDateTime.Minutes = 0; + ++aDateTime.Hours; + } + // if overflow goes into date, I give up } OUString Comment::getAuthor ( const CommentAuthorList& list ) diff --git a/qadevOOo/tests/java/mod/_forms/ODatabaseForm.java b/qadevOOo/tests/java/mod/_forms/ODatabaseForm.java index 3b9bd8284ca7..9c884d95720c 100644 --- a/qadevOOo/tests/java/mod/_forms/ODatabaseForm.java +++ b/qadevOOo/tests/java/mod/_forms/ODatabaseForm.java @@ -636,11 +636,11 @@ public class ODatabaseForm extends TestCase { d.Day = 26; d.Month = 1; d.Year = 2001; params.add(d) ; Time t = new Time(); - t.Hours = 1; t.HundredthSeconds = 12; t.Minutes = 25; t.Seconds = 14; + t.Hours = 1; t.NanoSeconds = 123456789; t.Minutes = 25; t.Seconds = 14; params.add(t) ; DateTime dt = new DateTime(); dt.Day = 26; dt.Month = 1; dt.Year = 2001; dt.Hours = 1; - dt.HundredthSeconds = 12; dt.Minutes = 25; dt.Seconds = 14; + dt.NanoSeconds = 123456789; dt.Minutes = 25; dt.Seconds = 14; params.add(dt) ; tEnv.addObjRelation("XParameters.ParamValues", params); diff --git a/reportbuilder/java/org/libreoffice/report/SDBCReportData.java b/reportbuilder/java/org/libreoffice/report/SDBCReportData.java index 6019d94c8cb6..c05d6b8e4178 100644 --- a/reportbuilder/java/org/libreoffice/report/SDBCReportData.java +++ b/reportbuilder/java/org/libreoffice/report/SDBCReportData.java @@ -264,7 +264,7 @@ public class SDBCReportData implements DataSource str.append(' '); str.append(getTimeString(unoTs.Hours, unoTs.Minutes, unoTs.Seconds)); str.append('.'); - str.append(unoTs.HundredthSeconds); + str.append(String.format("%09d", unoTs.NanoSeconds)); ts = java.sql.Timestamp.valueOf(str.toString()); } else diff --git a/reportdesign/source/filter/xml/xmlControlProperty.cxx b/reportdesign/source/filter/xml/xmlControlProperty.cxx index aca8453b511d..7d4ec150a661 100644 --- a/reportdesign/source/filter/xml/xmlControlProperty.cxx +++ b/reportdesign/source/filter/xml/xmlControlProperty.cxx @@ -34,6 +34,7 @@ #include <tools/datetime.hxx> #include <unotools/datetime.hxx> #include <com/sun/star/util/DateTime.hpp> +#include <rtl/math.hxx> #define TYPE_DATE 1 #define TYPE_TIME 2 @@ -301,7 +302,7 @@ Any OXMLControlProperty::convertString(const ::com::sun::star::uno::Type& _rExpe ::com::sun::star::util::Date aDate = implGetDate(nValue); ::com::sun::star::util::DateTime aDateTime; - aDateTime.HundredthSeconds = aTime.HundredthSeconds; + aDateTime.NanoSeconds = aTime.NanoSeconds; aDateTime.Seconds = aTime.Seconds; aDateTime.Minutes = aTime.Minutes; aDateTime.Hours = aTime.Hours; @@ -329,10 +330,9 @@ Any OXMLControlProperty::convertString(const ::com::sun::star::uno::Type& _rExpe ::com::sun::star::util::Time OXMLControlProperty::implGetTime(double _nValue) { ::com::sun::star::util::Time aTime; - sal_uInt32 nIntValue = sal_Int32(_nValue * 8640000); - nIntValue *= 8640000; - aTime.HundredthSeconds = (sal_uInt16)( nIntValue % 100 ); - nIntValue /= 100; + sal_uInt64 nIntValue = ::rtl::math::round(_nValue * 86400000000000.0); + aTime.NanoSeconds = (sal_uInt16)( nIntValue % 1000000000 ); + nIntValue /= 1000000000; aTime.Seconds = (sal_uInt16)( nIntValue % 60 ); nIntValue /= 60; aTime.Minutes = (sal_uInt16)( nIntValue % 60 ); diff --git a/sax/qa/cppunit/test_converter.cxx b/sax/qa/cppunit/test_converter.cxx index 84d4da03db75..31e96bcf6cba 100644 --- a/sax/qa/cppunit/test_converter.cxx +++ b/sax/qa/cppunit/test_converter.cxx @@ -88,7 +88,7 @@ static bool eqDuration(util::Duration a, util::Duration b) { return a.Years == b.Years && a.Months == b.Months && a.Days == b.Days && a.Hours == b.Hours && a.Minutes == b.Minutes && a.Seconds == b.Seconds - && a.MilliSeconds == b.MilliSeconds + && a.NanoSeconds == b.NanoSeconds && a.Negative == b.Negative; } @@ -97,9 +97,10 @@ static void doTest(util::Duration const & rid, char const*const pis, { char const*const pos((i_pos) ? i_pos : pis); util::Duration od; - OUString is(OUString::createFromAscii(pis)); + OUString is(::rtl::OUString::createFromAscii(pis)); + SAL_INFO("sax.cppunit","about to convert '" << is << "'"); bool bSuccess = Converter::convertDuration(od, is); - SAL_INFO("sax.cppunit","" << od.Negative << " " << od.Years << "Y " << od.Months << "M " << od.Days << "D " << od.Hours << "H " << od.Minutes << "M " << od.Seconds << "S " << od.MilliSeconds << "m"); + SAL_INFO("sax.cppunit","" << (od.Negative ? "-" : "+") << " " << od.Years << "Y " << od.Months << "M " << od.Days << "D " << od.Hours << "H " << od.Minutes << "M " << od.Seconds << "S " << od.NanoSeconds << "n"); CPPUNIT_ASSERT(bSuccess); CPPUNIT_ASSERT(eqDuration(rid, od)); OUStringBuffer buf; @@ -113,7 +114,7 @@ static void doTestDurationF(char const*const pis) util::Duration od; bool bSuccess = Converter::convertDuration(od, OUString::createFromAscii(pis)); - SAL_INFO("sax.cppunit","" << od.Negative << " " << od.Years << "Y " << od.Months << "M " << od.Days << "D " << od.Hours << "H " << od.Minutes << "M " << od.Seconds << "S " << od.MilliSeconds << "H"); + SAL_INFO("sax.cppunit","" << (od.Negative ? "-" : "+") << " " << od.Years << "Y " << od.Months << "M " << od.Days << "D " << od.Hours << "H " << od.Minutes << "M " << od.Seconds << "S " << od.NanoSeconds << "n"); CPPUNIT_ASSERT(!bSuccess); } @@ -126,14 +127,15 @@ void ConverterTest::testDuration() doTest( util::Duration(false, 0, 0, 0, 52, 0, 0, 0), "PT52H" ); doTest( util::Duration(false, 0, 0, 0, 0, 717, 0, 0), "PT717M" ); doTest( util::Duration(false, 0, 0, 0, 0, 0, 121, 0), "PT121S" ); - doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 190), "PT0.19S" ); - doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 90), "PT0.09S" ); - doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 9), "PT0.009S" ); - doTest( util::Duration(false, 0, 0, 0, 0, 0, 9, 999), - "PT9.999999999999999999999999999999S", "PT9.999S" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 190000000), "PT0.19S", "PT0.190000000S"); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 90000000), "PT0.09S", "PT0.090000000S" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 9000000), "PT0.009S", "PT0.009000000S" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 9), "PT0.000000009S", "PT0.000000009S" ); + doTest( util::Duration(false, 0, 0, 0, 0, 0, 9, 999999999), + "PT9.999999999999999999999999999999S", "PT9.999999999S" ); doTest( util::Duration(true , 0, 0, 9999, 0, 0, 0, 0), "-P9999D" ); - doTest( util::Duration(true , 7, 6, 5, 4, 3, 2, 10), - "-P7Y6M5DT4H3M2.01S" ); + doTest( util::Duration(true , 7, 6, 5, 4, 3, 2, 10000000), + "-P7Y6M5DT4H3M2.01S", "-P7Y6M5DT4H3M2.010000000S" ); doTest( util::Duration(false, 0, 6, 0, 0, 3, 0, 0), "P6MT3M" ); doTest( util::Duration(false, 0, 0, 0, 0, 0, 0, 0), "P0D" ); doTestDurationF("1Y1M"); // invalid: no ^P @@ -155,7 +157,7 @@ static bool eqDateTime(util::DateTime a, util::DateTime b) { return a.Year == b.Year && a.Month == b.Month && a.Day == b.Day && a.Hours == b.Hours && a.Minutes == b.Minutes && a.Seconds == b.Seconds - && a.HundredthSeconds == b.HundredthSeconds; + && a.NanoSeconds == b.NanoSeconds; } static void doTest(util::DateTime const & rdt, char const*const pis, @@ -164,8 +166,9 @@ static void doTest(util::DateTime const & rdt, char const*const pis, char const*const pos((i_pos) ? i_pos : pis); OUString is(OUString::createFromAscii(pis)); util::DateTime odt; + SAL_INFO("sax.cppunit","about to convert '" << is << "'"); bool bSuccess( Converter::convertDateTime(odt, is) ); - SAL_INFO("sax.cppunit","Y:" << odt.Year << " M:" << odt.Month << " D:" << odt.Day << " H:" << odt.Hours << " M:" << odt.Minutes << " S:" << odt.Seconds << " H:" << odt.HundredthSeconds); + SAL_INFO("sax.cppunit","Y:" << odt.Year << " M:" << odt.Month << " D:" << odt.Day << " H:" << odt.Hours << " M:" << odt.Minutes << " S:" << odt.Seconds << " nS:" << odt.NanoSeconds); CPPUNIT_ASSERT(bSuccess); CPPUNIT_ASSERT(eqDateTime(rdt, odt)); OUStringBuffer buf; @@ -179,7 +182,7 @@ static void doTestDateTimeF(char const*const pis) util::DateTime odt; bool bSuccess = Converter::convertDateTime(odt, OUString::createFromAscii(pis)); - SAL_INFO("sax.cppunit","Y:" << odt.Year << " M:" << odt.Month << " D:" << odt.Day << " H:" << odt.Hours << "H M:" << odt.Minutes << " S:" << odt.Seconds << " H:" << odt.HundredthSeconds); + SAL_INFO("sax.cppunit","Y:" << odt.Year << " M:" << odt.Month << " D:" << odt.Day << " H:" << odt.Hours << "H M:" << odt.Minutes << " S:" << odt.Seconds << " nS:" << odt.NanoSeconds); CPPUNIT_ASSERT(!bSuccess); } @@ -201,16 +204,16 @@ void ConverterTest::testDateTime() doTest( util::DateTime(0, 0, 0, 0, 2, 1, 1)/*(0, 0, 12, 0, 1, 1, 1)*/, "0001-01-02T00:00:00+12:00", "0001-01-02T00:00:00" ); // "0001-01-01T12:00:00" ); - doTest( util::DateTime(99, 59, 59, 23, 31, 12, 9999), - "9999-12-31T23:59:59.99" ); - doTest( util::DateTime(99, 59, 59, 23, 31, 12, 9999), - "9999-12-31T23:59:59.99Z", "9999-12-31T23:59:59.99" ); - doTest( util::DateTime(99, 59, 59, 23, 31, 12, 9999), + doTest( util::DateTime(990000000, 59, 59, 23, 31, 12, 9999), + "9999-12-31T23:59:59.99", "9999-12-31T23:59:59.990000000" ); + doTest( util::DateTime(990000000, 59, 59, 23, 31, 12, 9999), + "9999-12-31T23:59:59.99Z", "9999-12-31T23:59:59.990000000" ); + doTest( util::DateTime(999999999, 59, 59, 23, 31, 12, 9999), "9999-12-31T23:59:59.9999999999999999999999999999999999999", - "9999-12-31T23:59:59.99" ); - doTest( util::DateTime(99, 59, 59, 23, 31, 12, 9999), + "9999-12-31T23:59:59.999999999" ); + doTest( util::DateTime(999999999, 59, 59, 23, 31, 12, 9999), "9999-12-31T23:59:59.9999999999999999999999999999999999999Z", - "9999-12-31T23:59:59.99" ); + "9999-12-31T23:59:59.999999999" ); doTest( util::DateTime(0, 0, 0, 0, 29, 2, 2000), // leap year "2000-02-29T00:00:00-00:00", "2000-02-29T00:00:00" ); doTest( util::DateTime(0, 0, 0, 0, 29, 2, 1600), // leap year diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx index 22fa9060b154..6b88e10fbc51 100644 --- a/sax/source/tools/converter.cxx +++ b/sax/source/tools/converter.cxx @@ -29,6 +29,8 @@ #include <rtl/ustrbuf.hxx> #include <rtl/math.hxx> +#include <algorithm> + using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::util; @@ -43,8 +45,7 @@ static const sal_Char* gpsPT = "pt"; static const sal_Char* gpsINCH = "in"; static const sal_Char* gpsPC = "pc"; -const sal_Int8 XML_MAXDIGITSCOUNT_TIME = 11; -const sal_Int8 XML_MAXDIGITSCOUNT_DATETIME = 6; +const sal_Int8 XML_MAXDIGITSCOUNT_TIME = 14; /** convert string to measure using optional min and max values*/ bool Converter::convertMeasure( sal_Int32& rValue, @@ -658,15 +659,15 @@ void Converter::convertDuration(OUStringBuffer& rBuffer, fValue *= 60; double fSecsValue = ::rtl::math::approxFloor (fValue); fValue -= fSecsValue; - double f100SecsValue; - if (fValue > 0.00001) - f100SecsValue = ::rtl::math::round( fValue, XML_MAXDIGITSCOUNT_TIME - 5); + double fNanoSecsValue; + if (fValue > 0.00000000001) + fNanoSecsValue = ::rtl::math::round( fValue, XML_MAXDIGITSCOUNT_TIME - 5); else - f100SecsValue = 0.0; + fNanoSecsValue = 0.0; - if (f100SecsValue == 1.0) + if (fNanoSecsValue == 1.0) { - f100SecsValue = 0.0; + fNanoSecsValue = 0.0; fSecsValue += 1.0; } if (fSecsValue >= 60.0) @@ -691,15 +692,15 @@ void Converter::convertDuration(OUStringBuffer& rBuffer, if (fSecsValue < 10) rBuffer.append( sal_Unicode('0')); rBuffer.append( sal_Int32( fSecsValue)); - if (f100SecsValue > 0.0) + if (fNanoSecsValue > 0.0) { - OUString a100th( ::rtl::math::doubleToUString( fValue, + OUString aNS( ::rtl::math::doubleToUString( fValue, rtl_math_StringFormat_F, XML_MAXDIGITSCOUNT_TIME - 5, '.', true)); - if ( a100th.getLength() > 2 ) + if ( aNS.getLength() > 2 ) { rBuffer.append( sal_Unicode('.')); - rBuffer.append( a100th.copy( 2 ) ); // strip 0. + rBuffer.append( aNS.copy( 2 ) ); // strip "0." } } rBuffer.append( sal_Unicode('S')); @@ -816,12 +817,10 @@ bool Converter::convertDuration(double& rfTime, double fHour = nHours; double fMin = nMins; double fSec = nSecs; - double fSec100 = 0.0; double fFraction = sDoubleStr.toDouble(); fTempTime = fHour / 24; fTempTime += fMin / (24 * 60); fTempTime += fSec / (24 * 60 * 60); - fTempTime += fSec100 / (24 * 60 * 60 * 60); fTempTime += fFraction / (24 * 60 * 60); // negative duration? @@ -835,7 +834,7 @@ bool Converter::convertDuration(double& rfTime, return bSuccess; } -/** convert util::Duration to ISO "duration" string */ +/** convert util::Duration to ISO8601 "duration" string */ void Converter::convertDuration(OUStringBuffer& rBuffer, const ::util::Duration& rDuration) { @@ -844,9 +843,9 @@ void Converter::convertDuration(OUStringBuffer& rBuffer, rBuffer.append(sal_Unicode('-')); } rBuffer.append(sal_Unicode('P')); - const bool bHaveDate(static_cast<sal_Int32>(rDuration.Years) - +static_cast<sal_Int32>(rDuration.Months) - +static_cast<sal_Int32>(rDuration.Days)); + const bool bHaveDate(rDuration.Years != 0 || + rDuration.Months != 0 || + rDuration.Days != 0); if (rDuration.Years) { rBuffer.append(static_cast<sal_Int32>(rDuration.Years)); @@ -862,10 +861,10 @@ void Converter::convertDuration(OUStringBuffer& rBuffer, rBuffer.append(static_cast<sal_Int32>(rDuration.Days)); rBuffer.append(sal_Unicode('D')); } - const sal_Int32 nMSecs(static_cast<sal_Int32>(rDuration.Seconds) - + static_cast<sal_Int32>(rDuration.MilliSeconds)); - if (static_cast<sal_Int32>(rDuration.Hours) + - static_cast<sal_Int32>(rDuration.Minutes) + nMSecs) + if ( rDuration.Hours != 0 + || rDuration.Minutes != 0 + || rDuration.Seconds != 0 + || rDuration.NanoSeconds != 0 ) { rBuffer.append(sal_Unicode('T')); // time separator if (rDuration.Hours) @@ -878,37 +877,19 @@ void Converter::convertDuration(OUStringBuffer& rBuffer, rBuffer.append(static_cast<sal_Int32>(rDuration.Minutes)); rBuffer.append(sal_Unicode('M')); } - if (nMSecs) + if (rDuration.Seconds != 0 || rDuration.NanoSeconds != 0) { // seconds must not be omitted (i.e. ".42S" is not valid) rBuffer.append(static_cast<sal_Int32>(rDuration.Seconds)); - if (rDuration.MilliSeconds) + if (rDuration.NanoSeconds) { - rBuffer.append(sal_Unicode('.')); - const sal_Int32 nMilliSeconds(rDuration.MilliSeconds % 1000); - if (nMilliSeconds < 100) - { - rBuffer.append(sal_Unicode('0')); - } - if (nMilliSeconds < 10) - { - rBuffer.append(sal_Unicode('0')); - } - if (0 == (nMilliSeconds % 10)) - { - if (0 == (nMilliSeconds % 100)) - { - rBuffer.append(nMilliSeconds / 100); - } - else - { - rBuffer.append(nMilliSeconds / 10); - } - } - else - { - rBuffer.append(nMilliSeconds); - } + OSL_ENSURE(rDuration.NanoSeconds < 1000000000,"NanoSeconds cannot be more than 999 999 999"); + rBuffer.append('.'); + std::ostringstream ostr; + ostr.fill('0'); + ostr.width(9); + ostr << rDuration.NanoSeconds; + rBuffer.append(OUString::createFromAscii(ostr.str().c_str())); } rBuffer.append(sal_Unicode('S')); } @@ -928,7 +909,7 @@ readUnsignedNumber(const OUString & rString, sal_Int32 & io_rnPos, sal_Int32 & o_rNumber) { bool bOverflow(false); - sal_Int32 nTemp(0); + sal_Int64 nTemp(0); sal_Int32 nPos(io_rnPos); while (nPos < rString.getLength()) @@ -938,7 +919,7 @@ readUnsignedNumber(const OUString & rString, { nTemp *= 10; nTemp += (c - sal_Unicode('0')); - if (nTemp >= SAL_MAX_INT16) + if (nTemp >= SAL_MAX_INT32) { bOverflow = true; } @@ -961,6 +942,50 @@ readUnsignedNumber(const OUString & rString, return (bOverflow) ? R_OVERFLOW : R_SUCCESS; } +static Result +readUnsignedNumberMaxDigits(int maxDigits, + const ::rtl::OUString & rString, sal_Int32 & io_rnPos, + sal_Int32 & o_rNumber) +{ + bool bOverflow(false); + sal_Int64 nTemp(0); + sal_Int32 nPos(io_rnPos); + OSL_ENSURE(maxDigits >= 0, "negative amount of digits makes no sense"); + + while (nPos < rString.getLength()) + { + const sal_Unicode c = rString[nPos]; + if ((sal_Unicode('0') <= c) && (c <= sal_Unicode('9'))) + { + if (maxDigits > 0) + { + nTemp *= 10; + nTemp += (c - sal_Unicode('0')); + if (nTemp >= SAL_MAX_INT32) + { + bOverflow = true; + } + --maxDigits; + } + } + else + { + break; + } + ++nPos; + } + + if (io_rnPos == nPos) // read something? + { + o_rNumber = -1; + return R_NOTHING; + } + + io_rnPos = nPos; + o_rNumber = nTemp; + return (bOverflow) ? R_OVERFLOW : R_SUCCESS; +} + static bool readDurationT(const OUString & rString, sal_Int32 & io_rnPos) { @@ -1003,7 +1028,7 @@ readDurationComponent(const OUString & rString, return true; } -/** convert ISO "duration" string to util::Duration */ +/** convert ISO8601 "duration" string to util::Duration */ bool Converter::convertDuration(util::Duration& rDuration, const OUString& rString) { @@ -1035,7 +1060,7 @@ bool Converter::convertDuration(util::Duration& rDuration, sal_Int32 nHours(0); sal_Int32 nMinutes(0); sal_Int32 nSeconds(0); - sal_Int32 nMilliSeconds(0); + sal_Int32 nNanoSeconds(0); bTimePart = readDurationT(string, nPos); bSuccess = (R_SUCCESS == readUnsignedNumber(string, nPos, nTemp)); @@ -1080,7 +1105,8 @@ bool Converter::convertDuration(util::Duration& rDuration, // eeek! seconds are icky. if ((nPos < string.getLength()) && bSuccess) { - if (sal_Unicode('.') == string[nPos]) + if (string[nPos] == sal_Unicode('.') || + string[nPos] == sal_Unicode(',')) { ++nPos; if (-1 != nTemp) @@ -1088,27 +1114,15 @@ bool Converter::convertDuration(util::Duration& rDuration, nSeconds = nTemp; nTemp = -1; const sal_Int32 nStart(nPos); - bSuccess = - (R_NOTHING != readUnsignedNumber(string, nPos, nTemp)); + bSuccess = readUnsignedNumberMaxDigits(9, string, nPos, nTemp) == R_SUCCESS; if ((nPos < string.getLength()) && bSuccess) { if (-1 != nTemp) { - nTemp = -1; - const sal_Int32 nDigits = nPos - nStart; - OSL_ENSURE(nDigits > 0, "bad code monkey"); - const sal_Unicode cZero('0'); - nMilliSeconds = 100 * (string[nStart] - cZero); - if (nDigits >= 2) - { - nMilliSeconds += 10 * - (string[nStart+1] - cZero); - if (nDigits >= 3) - { - nMilliSeconds += (string[nStart+2] - cZero); - } - } - + const sal_Int32 nDigits = std::min<sal_Int32>(nPos - nStart, 9); + OSL_ENSURE(nDigits > 0, "bad code monkey: negative digits"); + nNanoSeconds=static_cast<double>(nTemp)*(1000000000.0/pow(10.0,nDigits)); + nTemp=-1; if (sal_Unicode('S') == string[nPos]) { ++nPos; @@ -1164,7 +1178,7 @@ bool Converter::convertDuration(util::Duration& rDuration, rDuration.Hours = static_cast<sal_Int16>(nHours); rDuration.Minutes = static_cast<sal_Int16>(nMinutes); rDuration.Seconds = static_cast<sal_Int16>(nSeconds); - rDuration.MilliSeconds = static_cast<sal_Int16>(nMilliSeconds); + rDuration.NanoSeconds = static_cast<sal_Int32>(nNanoSeconds); } return bSuccess; @@ -1232,13 +1246,14 @@ void Converter::convertDateTime( i_rBuffer.append(zero); } i_rBuffer.append( static_cast<sal_Int32>(i_rDateTime.Seconds) ); - if( i_rDateTime.HundredthSeconds > 0 ) { + if( i_rDateTime.NanoSeconds > 0 ) { + OSL_ENSURE(i_rDateTime.NanoSeconds < 1000000000,"NanoSeconds cannot be more than 999 999 999"); i_rBuffer.append(dot); - if( i_rDateTime.HundredthSeconds < 10 ) { - i_rBuffer.append(zero); - } - i_rBuffer.append( - static_cast<sal_Int32>(i_rDateTime.HundredthSeconds) ); + std::ostringstream ostr; + ostr.fill('0'); + ostr.width(9); + ostr << i_rDateTime.NanoSeconds; + i_rBuffer.append(OUString::createFromAscii(ostr.str().c_str())); } } } @@ -1259,7 +1274,7 @@ bool Converter::convertDateTime( util::DateTime& rDateTime, rDateTime.Hours = 0; rDateTime.Minutes = 0; rDateTime.Seconds = 0; - rDateTime.HundredthSeconds = 0; + rDateTime.NanoSeconds = 0; } return true; } @@ -1381,7 +1396,7 @@ bool Converter::convertDateOrDateTime( sal_Int32 nHours(0); sal_Int32 nMinutes(0); sal_Int32 nSeconds(0); - sal_Int32 nMilliSeconds(0); + sal_Int32 nNanoSeconds(0); if (bSuccess && bHaveTime) { { @@ -1419,37 +1434,26 @@ bool Converter::convertDateOrDateTime( bSuccess &= (0 <= nSeconds) && (nSeconds < 60); } if (bSuccess && (nPos < string.getLength()) && - (sal_Unicode('.') == string[nPos])) // fraction separator + (sal_Unicode('.') == string[nPos] || sal_Unicode(',') == string[nPos])) // fraction separator { ++nPos; const sal_Int32 nStart(nPos); sal_Int32 nTemp(0); - if (R_NOTHING == readUnsignedNumber(string, nPos, nTemp)) + if (R_NOTHING == readUnsignedNumberMaxDigits(9, string, nPos, nTemp)) { bSuccess = false; } if (bSuccess) { - // cannot use nTemp because of possible leading zeros - // and possible overflow => read digits directly - const sal_Int32 nDigits(nPos - nStart); + const sal_Int32 nDigits = std::min<sal_Int32>(nPos - nStart, 9); OSL_ENSURE(nDigits > 0, "bad code monkey"); - const sal_Unicode cZero('0'); - nMilliSeconds = 100 * (string[nStart] - cZero); - if (nDigits >= 2) - { - nMilliSeconds += 10 * (string[nStart+1] - cZero); - if (nDigits >= 3) - { - nMilliSeconds += (string[nStart+2] - cZero); - } - } + nNanoSeconds=static_cast<double>(nTemp)*(1000000000.0/pow(10.0,nDigits)); } } if (bSuccess && (nHours == 24)) { - if (!((0 == nMinutes) && (0 == nSeconds) && (0 == nMilliSeconds))) + if (!((0 == nMinutes) && (0 == nSeconds) && (0 == nNanoSeconds))) { bSuccess = false; // only 24:00:00 is valid } @@ -1533,9 +1537,7 @@ bool Converter::convertDateOrDateTime( rDateTime.Hours = static_cast<sal_uInt16>(nHours); rDateTime.Minutes = static_cast<sal_uInt16>(nMinutes); rDateTime.Seconds = static_cast<sal_uInt16>(nSeconds); - // util::DateTime does not support 3 decimal digits of precision! - rDateTime.HundredthSeconds = - static_cast<sal_uInt16>(nMilliSeconds / 10); + rDateTime.NanoSeconds = static_cast<sal_uInt32>(nNanoSeconds); rbDateTime = true; } else @@ -2279,7 +2281,7 @@ bool Converter::convertAny(OUStringBuffer& rsValue, aTempValue.Day = aDate.Day; aTempValue.Month = aDate.Month; aTempValue.Year = aDate.Year; - aTempValue.HundredthSeconds = 0; + aTempValue.NanoSeconds = 0; aTempValue.Seconds = 0; aTempValue.Minutes = 0; aTempValue.Hours = 0; @@ -2294,7 +2296,7 @@ bool Converter::convertAny(OUStringBuffer& rsValue, aTempValue.Days = 0; aTempValue.Months = 0; aTempValue.Years = 0; - aTempValue.MilliSeconds = aTime.HundredthSeconds * 10; + aTempValue.NanoSeconds = aTime.NanoSeconds; aTempValue.Seconds = aTime.Seconds; aTempValue.Minutes = aTime.Minutes; aTempValue.Hours = aTime.Hours; diff --git a/sc/inc/chgtrack.hxx b/sc/inc/chgtrack.hxx index 38b683c50d5d..aef13cf562c8 100644 --- a/sc/inc/chgtrack.hxx +++ b/sc/inc/chgtrack.hxx @@ -925,7 +925,7 @@ class ScChangeTrack : public utl::ConfigurationListener bool bInDeleteTop:1; bool bInPasteCut:1; bool bUseFixDateTime:1; - bool bTime100thSeconds:1; + bool bTimeNanoSeconds:1; // not implemented, prevent usage ScChangeTrack( const ScChangeTrack& ); @@ -1235,9 +1235,9 @@ public: // If time stamps of actions of this // ChangeTrack and a second one are to be - // compared including 100th seconds. - void SetTime100thSeconds( bool bVal ) { bTime100thSeconds = bVal; } - bool IsTime100thSeconds() const { return bTime100thSeconds; } + // compared including nanoseconds. + void SetTimeNanoSeconds( bool bVal ) { bTimeNanoSeconds = bVal; } + bool IsTimeNanoSeconds() const { return bTimeNanoSeconds; } void AppendCloned( ScChangeAction* pAppend ); SC_DLLPUBLIC ScChangeTrack* Clone( ScDocument* pDocument ) const; diff --git a/sc/source/core/data/dbdocutl.cxx b/sc/source/core/data/dbdocutl.cxx index eb244f779eb3..a03250aae21e 100644 --- a/sc/source/core/data/dbdocutl.cxx +++ b/sc/source/core/data/dbdocutl.cxx @@ -109,8 +109,10 @@ void ScDatabaseDocUtil::PutData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB NUMBERFORMAT_TIME, ScGlobal::eLnge ); util::Time aTime = xRow->getTime(nRowPos); - nVal = ( aTime.Hours * 3600 + aTime.Minutes * 60 + - aTime.Seconds + aTime.HundredthSeconds / 100.0 ) / DATE_TIME_FACTOR; + nVal = aTime.Hours / static_cast<double>(::Time::hourPerDay) + + aTime.Minutes / static_cast<double>(::Time::minutePerDay) + + aTime.Seconds / static_cast<double>(::Time::secondPerDay) + + aTime.NanoSeconds / static_cast<double>(::Time::nanoSecPerDay); bEmptyFlag = xRow->wasNull(); bValue = sal_True; } @@ -125,8 +127,10 @@ void ScDatabaseDocUtil::PutData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB util::DateTime aStamp = xRow->getTimestamp(nRowPos); nVal = ( Date( aStamp.Day, aStamp.Month, aStamp.Year ) - *pFormTable->GetNullDate() ) + - ( aStamp.Hours * 3600 + aStamp.Minutes * 60 + - aStamp.Seconds + aStamp.HundredthSeconds / 100.0 ) / DATE_TIME_FACTOR; + aStamp.Hours / static_cast<double>(::Time::hourPerDay) + + aStamp.Minutes / static_cast<double>(::Time::minutePerDay) + + aStamp.Seconds / static_cast<double>(::Time::secondPerDay) + + aStamp.NanoSeconds / static_cast<double>(::Time::nanoSecPerDay); bEmptyFlag = xRow->wasNull(); bValue = sal_True; } diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index c8f3fffbe923..703317003fd3 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -104,8 +104,6 @@ using ::com::sun::star::beans::XPropertySet; namespace { -const double D_TIMEFACTOR = 86400.0; - /** * Database connection implementation for UNO database API. Note that in * the UNO database API, column index is 1-based, whereas the interface @@ -220,8 +218,10 @@ void DBConnector::getValue(long nCol, ScDPItemData &rData, short& rNumType) cons rNumType = NUMBERFORMAT_TIME; util::Time aTime = mxRow->getTime(nCol+1); - fValue = ( aTime.Hours * 3600 + aTime.Minutes * 60 + - aTime.Seconds + aTime.HundredthSeconds / 100.0 ) / D_TIMEFACTOR; + fValue = aTime.Hours / static_cast<double>(::Time::hourPerDay) + + aTime.Minutes / static_cast<double>(::Time::minutePerDay) + + aTime.Seconds / static_cast<double>(::Time::secondPerDay) + + aTime.NanoSeconds / static_cast<double>(::Time::nanoSecPerDay); rData.SetValue(fValue); break; } @@ -231,8 +231,10 @@ void DBConnector::getValue(long nCol, ScDPItemData &rData, short& rNumType) cons util::DateTime aStamp = mxRow->getTimestamp(nCol+1); fValue = ( Date( aStamp.Day, aStamp.Month, aStamp.Year ) - maNullDate ) + - ( aStamp.Hours * 3600 + aStamp.Minutes * 60 + - aStamp.Seconds + aStamp.HundredthSeconds / 100.0 ) / D_TIMEFACTOR; + aStamp.Hours / static_cast<double>(::Time::hourPerDay) + + aStamp.Minutes / static_cast<double>(::Time::minutePerDay) + + aStamp.Seconds / static_cast<double>(::Time::secondPerDay) + + aStamp.NanoSeconds / static_cast<double>(::Time::nanoSecPerDay); rData.SetValue(fValue); break; } diff --git a/sc/source/core/tool/chgtrack.cxx b/sc/source/core/tool/chgtrack.cxx index 5425056769e0..254e423832b7 100644 --- a/sc/source/core/tool/chgtrack.cxx +++ b/sc/source/core/tool/chgtrack.cxx @@ -2232,7 +2232,7 @@ void ScChangeTrack::Init() bInDeleteUndo = false; bInPasteCut = false; bUseFixDateTime = false; - bTime100thSeconds = true; + bTimeNanoSeconds = true; const SvtUserOptions& rUserOpt = SC_MOD()->GetUserOptions(); OUStringBuffer aBuf; @@ -4556,7 +4556,7 @@ ScChangeTrack* ScChangeTrack::Clone( ScDocument* pDocument ) const } ScChangeTrack* pClonedTrack = new ScChangeTrack( pDocument ); - pClonedTrack->SetTime100thSeconds( IsTime100thSeconds() ); + pClonedTrack->SetTimeNanoSeconds( IsTimeNanoSeconds() ); // clone generated actions ::std::stack< const ScChangeAction* > aGeneratedStack; diff --git a/sc/source/core/tool/chgviset.cxx b/sc/source/core/tool/chgviset.cxx index 06f1f292f9c0..e924a06053d4 100644 --- a/sc/source/core/tool/chgviset.cxx +++ b/sc/source/core/tool/chgviset.cxx @@ -138,7 +138,7 @@ void ScChangeViewSettings::AdjustDateMode( const ScDocument& rDoc ) // all together during the gap between those two times. aFirstDateTime += Time( 0, 1 ); aFirstDateTime.SetSec(0); - aFirstDateTime.Set100Sec(0); + aFirstDateTime.SetNanoSec(0); } } if ( !pLast ) diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index ad4daa7443e8..5743f1d5f2f2 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -51,6 +51,7 @@ using namespace formula; #define SCdEpsilon 1.0E-7 +#define D_TIMEFACTOR static_cast<double>(::Time::secondPerDay) //----------------------------------------------------------------------------- // Datum und Zeit @@ -113,10 +114,10 @@ void ScInterpreter::ScGetActTime() Date aActDate( Date::SYSTEM ); long nDiff = aActDate - *(pFormatter->GetNullDate()); Time aActTime( Time::SYSTEM ); - double nTime = ((double)aActTime.Get100Sec() / 100 + - (double)(aActTime.GetSec() + - (aActTime.GetMin() * 60) + - (aActTime.GetHour() * 3600))) / DATE_TIME_FACTOR; + double nTime = aActTime.GetHour() / static_cast<double>(::Time::hourPerDay) + + aActTime.GetMin() / static_cast<double>(::Time::minutePerDay) + + aActTime.GetSec() / static_cast<double>(::Time::secondPerDay) + + aActTime.GetNanoSec() / static_cast<double>(::Time::nanoSecPerDay); PushDouble( (double) nDiff + nTime ); } @@ -149,8 +150,8 @@ void ScInterpreter::ScGetMin() RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScGetMin" ); double fTime = GetDouble(); fTime -= ::rtl::math::approxFloor(fTime); // Datumsanteil weg - long nVal = (long)::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5) % 3600; - PushDouble( (double) (nVal/60) ); + long nVal = (long)::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5) % ::Time::secondPerHour; + PushDouble( (double) (nVal / ::Time::secondPerMinute) ); } void ScInterpreter::ScGetSec() @@ -158,7 +159,7 @@ void ScInterpreter::ScGetSec() RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScGetSec" ); double fTime = GetDouble(); fTime -= ::rtl::math::approxFloor(fTime); // Datumsanteil weg - long nVal = (long)::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5) % 60; + long nVal = (long)::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5) % ::Time::secondPerMinute; PushDouble( (double) nVal ); } @@ -167,7 +168,7 @@ void ScInterpreter::ScGetHour() RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "er", "ScInterpreter::ScGetHour" ); double fTime = GetDouble(); fTime -= ::rtl::math::approxFloor(fTime); // Datumsanteil weg - long nVal = (long)::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5) / 3600; + long nVal = (long)::rtl::math::approxFloor(fTime*DATE_TIME_FACTOR+0.5) / ::Time::secondPerHour; PushDouble((double) nVal); } @@ -288,7 +289,7 @@ void ScInterpreter::ScGetTime() double nSec = GetDouble(); double nMin = GetDouble(); double nHour = GetDouble(); - double fTime = fmod( (nHour * 3600) + (nMin * 60) + nSec, DATE_TIME_FACTOR) / DATE_TIME_FACTOR; + double fTime = fmod( (nHour * ::Time::secondPerHour) + (nMin * ::Time::secondPerMinute) + nSec, DATE_TIME_FACTOR) / DATE_TIME_FACTOR; if (fTime < 0) PushIllegalArgument(); else diff --git a/sc/source/filter/html/htmlexp.cxx b/sc/source/filter/html/htmlexp.cxx index cb4b1645df07..d7dd473e23ea 100644 --- a/sc/source/filter/html/htmlexp.cxx +++ b/sc/source/filter/html/htmlexp.cxx @@ -169,7 +169,7 @@ static void lcl_AddStamp( String& rStr, const String& rName, { Date aD(rDateTime.Day, rDateTime.Month, rDateTime.Year); Time aT(rDateTime.Hours, rDateTime.Minutes, rDateTime.Seconds, - rDateTime.HundredthSeconds); + rDateTime.NanoSeconds); DateTime aDateTime(aD,aT); String aStrDate = rLoc.getDate( aDateTime ); diff --git a/sc/source/filter/oox/unitconverter.cxx b/sc/source/filter/oox/unitconverter.cxx index 632103b05135..20d9c487258c 100644 --- a/sc/source/filter/oox/unitconverter.cxx +++ b/sc/source/filter/oox/unitconverter.cxx @@ -58,10 +58,10 @@ inline sal_Int32 lclIsLeapYear( sal_Int32 nYear ) return ((nYear % 4) == 0) && (((nYear % 100) != 0) || ((nYear % 400) == 0)); } -void lclSkipYearBlock( sal_Int32& ornDays, sal_uInt16& ornYear, sal_Int32 nDaysInBlock, sal_Int32 nYearsPerBlock, sal_Int32 nMaxBlocks ) +void lclSkipYearBlock( sal_Int32& ornDays, sal_Int16& ornYear, sal_Int32 nDaysInBlock, sal_Int32 nYearsPerBlock, sal_Int32 nMaxBlocks ) { sal_Int32 nBlocks = ::std::min< sal_Int32 >( ornDays / nDaysInBlock, nMaxBlocks ); - ornYear = static_cast< sal_uInt16 >( ornYear + nYearsPerBlock * nBlocks ); + ornYear = static_cast< sal_Int16 >( ornYear + nYearsPerBlock * nBlocks ); ornDays -= nBlocks * nDaysInBlock; } diff --git a/sc/source/filter/xcl97/XclExpChangeTrack.cxx b/sc/source/filter/xcl97/XclExpChangeTrack.cxx index 9b0767aadfbb..708d7642e853 100644 --- a/sc/source/filter/xcl97/XclExpChangeTrack.cxx +++ b/sc/source/filter/xcl97/XclExpChangeTrack.cxx @@ -49,10 +49,10 @@ static OString lcl_DateTimeToOString( const DateTime& rDateTime ) { char sBuf[ 200 ]; snprintf( sBuf, sizeof( sBuf ), - "%d-%02d-%02dT%02d:%02d:%02d.%02dZ", + "%d-%02d-%02dT%02d:%02d:%02d.%09dZ", rDateTime.GetYear(), rDateTime.GetMonth(), rDateTime.GetDay(), rDateTime.GetHour(), rDateTime.GetMin(), rDateTime.GetSec(), - rDateTime.Get100Sec() ); + rDateTime.GetNanoSec() ); return OString( sBuf ); } @@ -624,7 +624,7 @@ XclExpChTrAction::XclExpChTrAction( bForceInfo( false ) { aDateTime.SetSec( 0 ); - aDateTime.Set100Sec( 0 ); + aDateTime.SetNanoSec( 0 ); } XclExpChTrAction::~XclExpChTrAction() diff --git a/sc/source/filter/xcl97/XclImpChangeTrack.cxx b/sc/source/filter/xcl97/XclImpChangeTrack.cxx index 976c1f83d451..948543a595eb 100644 --- a/sc/source/filter/xcl97/XclImpChangeTrack.cxx +++ b/sc/source/filter/xcl97/XclImpChangeTrack.cxx @@ -128,7 +128,7 @@ void XclImpChangeTrack::ReadDateTime( DateTime& rDateTime ) rDateTime.SetHour( nHour ); rDateTime.SetMin( nMin ); rDateTime.SetSec( nSec ); - rDateTime.Set100Sec( 0 ); + rDateTime.SetNanoSec( 0 ); } sal_Bool XclImpChangeTrack::CheckRecord( sal_uInt16 nOpCode ) diff --git a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx index 6caf7b05c81d..a28dd7725153 100644 --- a/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx +++ b/sc/source/filter/xml/XMLChangeTrackingImportHelper.cxx @@ -428,13 +428,13 @@ void ScXMLChangeTrackingImportHelper::EndChangeAction() void ScXMLChangeTrackingImportHelper::ConvertInfo(const ScMyActionInfo& aInfo, String& rUser, DateTime& aDateTime) { Date aDate(aInfo.aDateTime.Day, aInfo.aDateTime.Month, aInfo.aDateTime.Year); - Time aTime(aInfo.aDateTime.Hours, aInfo.aDateTime.Minutes, aInfo.aDateTime.Seconds, aInfo.aDateTime.HundredthSeconds); + Time aTime(aInfo.aDateTime.Hours, aInfo.aDateTime.Minutes, aInfo.aDateTime.Seconds, aInfo.aDateTime.NanoSeconds); aDateTime.SetDate( aDate.GetDate() ); aDateTime.SetTime( aTime.GetTime() ); - // old files didn't store 100th seconds, enable again - if ( aInfo.aDateTime.HundredthSeconds ) - pTrack->SetTime100thSeconds( true ); + // old files didn't store nanoseconds, enable again + if ( aInfo.aDateTime.NanoSeconds ) + pTrack->SetTimeNanoSeconds( true ); const std::set<OUString>& rUsers = pTrack->GetUserCollection(); std::set<OUString>::const_iterator it = rUsers.find(aInfo.sUser); @@ -795,8 +795,8 @@ void ScXMLChangeTrackingImportHelper::CreateChangeTrack(ScDocument* pTempDoc) if (pDoc) { pTrack = new ScChangeTrack(pDoc, aUsers); - // old files didn't store 100th seconds, disable until encountered - pTrack->SetTime100thSeconds( false ); + // old files didn't store nanoseconds, disable until encountered + pTrack->SetTimeNanoSeconds( false ); ScMyActions::iterator aItr(aActions.begin()); ScMyActions::iterator aEndItr(aActions.end()); diff --git a/sc/source/filter/xml/XMLConverter.cxx b/sc/source/filter/xml/XMLConverter.cxx index a705c0a55d0f..ae58ceff0e31 100644 --- a/sc/source/filter/xml/XMLConverter.cxx +++ b/sc/source/filter/xml/XMLConverter.cxx @@ -349,13 +349,13 @@ void ScXMLConverter::ConvertCoreToAPIDateTime(const DateTime& aDateTime, util::D rDateTime.Hours = aDateTime.GetHour(); rDateTime.Minutes = aDateTime.GetMin(); rDateTime.Seconds = aDateTime.GetSec(); - rDateTime.HundredthSeconds = aDateTime.Get100Sec(); + rDateTime.NanoSeconds = aDateTime.GetNanoSec(); } void ScXMLConverter::ConvertAPIToCoreDateTime(const util::DateTime& aDateTime, DateTime& rDateTime) { Date aDate(aDateTime.Day, aDateTime.Month, aDateTime.Year); - Time aTime(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds); + Time aTime(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.NanoSeconds); DateTime aTempDateTime (aDate, aTime); rDateTime = aTempDateTime; } diff --git a/sc/source/ui/docshell/docsh3.cxx b/sc/source/ui/docshell/docsh3.cxx index d64966bc9299..afa49ba356b0 100644 --- a/sc/source/ui/docshell/docsh3.cxx +++ b/sc/source/ui/docshell/docsh3.cxx @@ -743,7 +743,7 @@ static inline sal_Bool lcl_Equal( const ScChangeAction* pA, const ScChangeAction pA->GetType() == pB->GetType() && pA->GetUser() == pB->GetUser() && (bIgnore100Sec ? - pA->GetDateTimeUTC().IsEqualIgnore100Sec( pB->GetDateTimeUTC() ) : + pA->GetDateTimeUTC().IsEqualIgnoreNanoSec( pB->GetDateTimeUTC() ) : pA->GetDateTimeUTC() == pB->GetDateTimeUTC()); // State nicht vergleichen, falls eine alte Aenderung akzeptiert wurde } @@ -762,7 +762,7 @@ static bool lcl_FindAction( ScDocument* pDoc, const ScChangeAction* pAction, ScD if ( pAction->GetType() == pA->GetType() && pAction->GetUser() == pA->GetUser() && (bIgnore100Sec ? - pAction->GetDateTimeUTC().IsEqualIgnore100Sec( pA->GetDateTimeUTC() ) : + pAction->GetDateTimeUTC().IsEqualIgnoreNanoSec( pA->GetDateTimeUTC() ) : pAction->GetDateTimeUTC() == pA->GetDateTimeUTC() ) && pAction->GetBigRange() == pA->GetBigRange() ) { @@ -807,9 +807,9 @@ void ScDocShell::MergeDocument( ScDocument& rOtherDoc, bool bShared, bool bCheck } } - // include 100th seconds in compare? - sal_Bool bIgnore100Sec = !pSourceTrack->IsTime100thSeconds() || - !pThisTrack->IsTime100thSeconds(); + // include Nano seconds in compare? + sal_Bool bIgnore100Sec = !pSourceTrack->IsTimeNanoSeconds() || + !pThisTrack->IsTimeNanoSeconds(); // gemeinsame Ausgangsposition suchen sal_uLong nFirstNewNumber = 0; @@ -1189,7 +1189,7 @@ bool ScDocShell::MergeSharedDocument( ScDocShell* pSharedDocShell ) aDocument.SetChangeViewSettings( aChangeViewSet ); // find first merge action in this document - sal_Bool bIgnore100Sec = !pThisTrack->IsTime100thSeconds() || !pSharedTrack->IsTime100thSeconds(); + sal_Bool bIgnore100Sec = !pThisTrack->IsTimeNanoSeconds() || !pSharedTrack->IsTimeNanoSeconds(); ScChangeAction* pThisAction = pThisTrack->GetFirst(); ScChangeAction* pSharedAction = pSharedTrack->GetFirst(); while ( lcl_Equal( pThisAction, pSharedAction, bIgnore100Sec ) ) diff --git a/sc/source/ui/miscdlgs/sharedocdlg.cxx b/sc/source/ui/miscdlgs/sharedocdlg.cxx index 12a72e0ee82d..86fc0a5583f8 100644 --- a/sc/source/ui/miscdlgs/sharedocdlg.cxx +++ b/sc/source/ui/miscdlgs/sharedocdlg.cxx @@ -209,7 +209,7 @@ void ScShareDocumentDlg::UpdateView() util::DateTime uDT(xDocProps->getModificationDate()); Date d(uDT.Day, uDT.Month, uDT.Year); - Time t(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time t(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); DateTime aDateTime(d,t); aString += ScGlobal::pLocaleData->getDate( aDateTime ); diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx index c42c119990ca..9fd7f1c81fb3 100644 --- a/sc/source/ui/unoobj/fielduno.cxx +++ b/sc/source/ui/unoobj/fielduno.cxx @@ -950,7 +950,7 @@ void ScEditFieldObj::setPropertyValueDateTime(const OUString& rName, const uno:: else if (rName == SC_UNONAME_DATETIME) { maDateTime = rVal.get<util::DateTime>(); - Time aTime(maDateTime.Hours, maDateTime.Minutes, maDateTime.Seconds, maDateTime.HundredthSeconds); + Time aTime(maDateTime.Hours, maDateTime.Minutes, maDateTime.Seconds, maDateTime.NanoSeconds); p->SetFixTime(aTime); } else if (rName == SC_UNONAME_NUMFMT) @@ -1012,7 +1012,7 @@ uno::Any ScEditFieldObj::getPropertyValueDateTime(const OUString& rName) maDateTime.Hours = 0; maDateTime.Minutes = 0; maDateTime.Seconds = 0; - maDateTime.HundredthSeconds = 0; + maDateTime.NanoSeconds = 0; return uno::makeAny(maDateTime); } @@ -1056,7 +1056,7 @@ uno::Any ScEditFieldObj::getPropertyValueDateTime(const OUString& rName) maDateTime.Hours = aT.GetHour(); maDateTime.Minutes = aT.GetMin(); maDateTime.Seconds = aT.GetSec(); - maDateTime.HundredthSeconds = aT.Get100Sec(); + maDateTime.NanoSeconds = aT.GetNanoSec(); return uno::makeAny(maDateTime); } diff --git a/sc/source/ui/view/viewfun6.cxx b/sc/source/ui/view/viewfun6.cxx index ec0f6d421c90..b61c9fffe0a6 100644 --- a/sc/source/ui/view/viewfun6.cxx +++ b/sc/source/ui/view/viewfun6.cxx @@ -250,10 +250,10 @@ void ScViewFunc::InsertCurrentTime(short nCellFmt, const OUString& rUndoStr) Date aActDate( Date::SYSTEM ); double fDate = aActDate - *pFormatter->GetNullDate(); Time aActTime( Time::SYSTEM ); - double fTime = - aActTime.Get100Sec() / 100.0 + aActTime.GetSec() + - (aActTime.GetMin() * 60.0) + (aActTime.GetHour() * 3600.0); - fTime /= DATE_TIME_FACTOR; + double fTime = aActTime.GetHour() / static_cast<double>(::Time::hourPerDay) + + aActTime.GetMin() / static_cast<double>(::Time::minutePerDay) + + aActTime.GetSec() / static_cast<double>(::Time::secondPerDay) + + aActTime.GetNanoSec() / static_cast<double>(::Time::nanoSecPerDay); pUndoMgr->EnterListAction(rUndoStr, rUndoStr); pDocSh->GetDocFunc().SetValueCell(aCurPos, fDate+fTime, true); diff --git a/scripting/source/pyprov/pythonscript.py b/scripting/source/pyprov/pythonscript.py index cab985177cc1..52ae89bbb295 100755 --- a/scripting/source/pyprov/pythonscript.py +++ b/scripting/source/pyprov/pythonscript.py @@ -226,7 +226,7 @@ def hasChanged( oldDate, newDate ): newDate.Hours > oldDate.Hours or \ newDate.Minutes > oldDate.Minutes or \ newDate.Seconds > oldDate.Seconds or \ - newDate.HundredthSeconds > oldDate.HundredthSeconds + newDate.NanoSeconds > oldDate.NanoSeconds def ensureSourceState( code ): if code.endswith(b"\n"): diff --git a/sd/source/filter/eppt/eppt.cxx b/sd/source/filter/eppt/eppt.cxx index 7bd42c74802c..dc0593837b2a 100644 --- a/sd/source/filter/eppt/eppt.cxx +++ b/sd/source/filter/eppt/eppt.cxx @@ -53,6 +53,7 @@ #include <sfx2/docinf.hxx> #include <oox/export/utils.hxx> #include <oox/ole/olehelper.hxx> +#include <rtl/math.hxx> using namespace com::sun::star; using namespace ::com::sun::star::uno; @@ -1124,7 +1125,7 @@ void ImplExportComments( uno::Reference< drawing::XDrawPage > xPage, SvMemoryStr if ( !sInitials.isEmpty() ) PPTWriter::WriteCString( rBinaryTagData10Atom, sInitials, 2 ); - sal_Int16 nMilliSeconds = aDateTime.HundredthSeconds * 10; + sal_Int16 nMilliSeconds = static_cast<sal_Int16>(::rtl::math::round(static_cast<double>(aDateTime.NanoSeconds) / 1000000000.0)); EscherExAtom aCommentAtom10( rBinaryTagData10Atom, EPP_CommentAtom10 ); rBinaryTagData10Atom << nIndex++ << aDateTime.Year diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index 724acfe6edfa..da791f33e2f9 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -1314,7 +1314,7 @@ bool PowerPointExport::WriteComments( sal_uInt32 nPageNum ) sal_Int32 nId = GetAuthorIdAndLastIndex ( xAnnotation->getAuthor(), nLastIndex ); char cDateTime[32]; - snprintf(cDateTime, 31, "%02d-%02d-%02dT%02d:%02d:%02d.%03d", aDateTime.Year, aDateTime.Month, aDateTime.Day, aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds); + snprintf(cDateTime, 31, "%02d-%02d-%02dT%02d:%02d:%02d.%09d", aDateTime.Year, aDateTime.Month, aDateTime.Day, aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.NanoSeconds); pFS->startElementNS( XML_p, XML_cm, XML_authorId, I32S( nId ), diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index e3fe236b591d..2153af4c2e7f 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -165,7 +165,7 @@ OUString getAnnotationDateTimeString( const Reference< XAnnotation >& xAnnotatio else if (aDate.IsValidAndGregorian() ) sRet = rLocalData.getDate(aDate); - Time aTime( aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.HundredthSeconds ); + Time aTime( aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds, aDateTime.NanoSeconds ); if(aTime.GetTime() != 0) sRet = sRet + " " + rLocalData.getTime( aTime,false ); } diff --git a/sd/source/ui/dlg/animobjs.cxx b/sd/source/ui/dlg/animobjs.cxx index 8735f44edc4b..e1e46157253a 100644 --- a/sd/source/ui/dlg/animobjs.cxx +++ b/sd/source/ui/dlg/animobjs.cxx @@ -1062,7 +1062,7 @@ void AnimationWindow::CreateAnimObj (::sd::View& rView ) for (size_t i = 0; i < nCount; ++i) { Time *const pTime = m_FrameList[i].second; - long nTime = pTime->Get100Sec(); + long nTime = pTime->GetNanoSec(); nTime += pTime->GetSec() * 100; BitmapEx const*const pBitmapEx = m_FrameList[i].first; diff --git a/sfx2/qa/complex/sfx2/DocumentProperties.java b/sfx2/qa/complex/sfx2/DocumentProperties.java index 17faed72d440..5db9174d7a23 100644 --- a/sfx2/qa/complex/sfx2/DocumentProperties.java +++ b/sfx2/qa/complex/sfx2/DocumentProperties.java @@ -349,7 +349,7 @@ public class DocumentProperties dur.Hours = 777; dur.Minutes = 666; dur.Seconds = 555; - dur.MilliSeconds = 444; + dur.NanoSeconds = 444444444; udpc.addProperty("Frobnicate", PropertyAttribute.REMOVABLE, b); udpc.addProperty("FrobDuration", PropertyAttribute.REMOVABLE, dur); @@ -426,7 +426,7 @@ public class DocumentProperties // this is now a Duration! Duration t_dur = new Duration(false, (short)0, (short)0, (short)0, t.Hours, t.Minutes, t.Seconds, - (short)(10 * t.HundredthSeconds)); + t.NanoSeconds); assertTrue("UserDefined time", eqDuration(t_dur, (Duration) udps.getPropertyValue("FrobDuration2"))); assertTrue("UserDefined date", eqDate(date, (Date) @@ -476,7 +476,7 @@ public class DocumentProperties return a.Year == b.Year && a.Month == b.Month && a.Day == b.Day && a.Hours == b.Hours && a.Minutes == b.Minutes && a.Seconds == b.Seconds - && a.HundredthSeconds == b.HundredthSeconds; + && a.NanoSeconds == b.NanoSeconds; } boolean eqDate(Date a, Date b) { @@ -486,14 +486,14 @@ public class DocumentProperties boolean eqTime(Time a, Time b) { return a.Hours == b.Hours && a.Minutes == b.Minutes && a.Seconds == b.Seconds - && a.HundredthSeconds == b.HundredthSeconds; + && a.NanoSeconds == b.NanoSeconds; } boolean eqDuration(Duration a, Duration b) { return a.Years == b.Years && a.Months == b.Months && a.Days == b.Days && a.Hours == b.Hours && a.Minutes == b.Minutes && a.Seconds == b.Seconds - && a.MilliSeconds == b.MilliSeconds + && a.NanoSeconds == b.NanoSeconds && a.Negative == b.Negative; } diff --git a/sfx2/source/appl/sfxpicklist.cxx b/sfx2/source/appl/sfxpicklist.cxx index 1da4614d1255..f18b1db0b3da 100644 --- a/sfx2/source/appl/sfxpicklist.cxx +++ b/sfx2/source/appl/sfxpicklist.cxx @@ -365,7 +365,7 @@ void SfxPickList::Notify( SfxBroadcaster&, const SfxHint& rHint ) xDocProps->setAuthor( SvtUserOptions().GetFullName() ); ::DateTime now( ::DateTime::SYSTEM ); xDocProps->setCreationDate( util::DateTime( - now.Get100Sec(), now.GetSec(), now.GetMin(), + now.GetNanoSec(), now.GetSec(), now.GetMin(), now.GetHour(), now.GetDay(), now.GetMonth(), now.GetYear() ) ); } diff --git a/sfx2/source/bastyp/frmhtmlw.cxx b/sfx2/source/bastyp/frmhtmlw.cxx index 1f24a5952288..e822d9d7dc0d 100644 --- a/sfx2/source/bastyp/frmhtmlw.cxx +++ b/sfx2/source/bastyp/frmhtmlw.cxx @@ -172,7 +172,7 @@ void SfxFrameHTMLWriter::Out_DocInfo( SvStream& rStrm, const String& rBaseURL, // created ::util::DateTime uDT = i_xDocProps->getCreationDate(); Date aD(uDT.Day, uDT.Month, uDT.Year); - Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); String sOut = OUString::number(aD.GetDate()); sOut += ';'; sOut += OUString::number(aT.GetTime()); @@ -188,7 +188,7 @@ void SfxFrameHTMLWriter::Out_DocInfo( SvStream& rStrm, const String& rBaseURL, // changed uDT = i_xDocProps->getModificationDate(); Date aD2(uDT.Day, uDT.Month, uDT.Year); - Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); sOut = OUString::number(aD2.GetDate()); sOut += ';'; sOut += OUString::number(aT2.GetTime()); diff --git a/sfx2/source/dialog/dinfdlg.cxx b/sfx2/source/dialog/dinfdlg.cxx index b198ca24822b..e13e557241cb 100644 --- a/sfx2/source/dialog/dinfdlg.cxx +++ b/sfx2/source/dialog/dinfdlg.cxx @@ -99,7 +99,7 @@ bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight) && i_rLeft.Hours == i_rRight.Hours && i_rLeft.Minutes == i_rRight.Minutes && i_rLeft.Seconds == i_rRight.Seconds - && i_rLeft.HundredthSeconds == i_rRight.HundredthSeconds; + && i_rLeft.NanoSeconds == i_rRight.NanoSeconds; } // STATIC DATA ----------------------------------------------------------- @@ -174,7 +174,7 @@ String ConvertDateTime_Impl( const String& rName, const util::DateTime& uDT, const LocaleDataWrapper& rWrapper ) { Date aD(uDT.Day, uDT.Month, uDT.Year); - Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); const String pDelim ( ", " ); String aStr( rWrapper.getDate( aD ) ); aStr += pDelim; @@ -352,7 +352,7 @@ void SfxDocumentInfoItem::resetUserData(const OUString & i_rAuthor) setAuthor(i_rAuthor); DateTime now( DateTime::SYSTEM ); setCreationDate( util::DateTime( - now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(), + now.GetNanoSec(), now.GetSec(), now.GetMin(), now.GetHour(), now.GetDay(), now.GetMonth(), now.GetYear() ) ); setModifiedBy(OUString()); setPrintedBy(OUString()); @@ -798,7 +798,7 @@ IMPL_LINK_NOARG(SfxDocumentPage, DeleteHdl) const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() ); DateTime now( DateTime::SYSTEM ); util::DateTime uDT( - now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(), + now.GetNanoSec(), now.GetSec(), now.GetMin(), now.GetHour(), now.GetDay(), now.GetMonth(), now.GetYear() ); m_pCreateValFt->SetText( ConvertDateTime_Impl( aName, uDT, rLocaleWrapper ) ); OUString aEmpty; @@ -1241,7 +1241,7 @@ DurationDialog_Impl::DurationDialog_Impl( aHourNF.SetValue(rDuration.Hours ); aMinuteNF.SetValue(rDuration.Minutes); aSecondNF.SetValue(rDuration.Seconds); - aMSecondNF.SetValue(rDuration.MilliSeconds); + aMSecondNF.SetValue(rDuration.NanoSeconds); } DurationDialog_Impl::~DurationDialog_Impl() @@ -1258,7 +1258,7 @@ util::Duration DurationDialog_Impl::GetDuration() const aRet.Hours = aHourNF.GetValue( ); aRet.Minutes = aMinuteNF.GetValue(); aRet.Seconds = aSecondNF.GetValue(); - aRet.MilliSeconds = aMSecondNF.GetValue(); + aRet.NanoSeconds = aMSecondNF.GetValue(); return aRet; } @@ -1752,7 +1752,7 @@ void CustomPropertiesWindow::AddLine( const OUString& sName, Any& rAny ) else if ( rAny >>= aTmpDateTime ) { pNewLine->m_aDateField.SetDate( Date( aTmpDateTime.Day, aTmpDateTime.Month, aTmpDateTime.Year ) ); - pNewLine->m_aTimeField.SetTime( Time( aTmpDateTime.Hours, aTmpDateTime.Minutes, aTmpDateTime.Seconds, aTmpDateTime.HundredthSeconds ) ); + pNewLine->m_aTimeField.SetTime( Time( aTmpDateTime.Hours, aTmpDateTime.Minutes, aTmpDateTime.Seconds, aTmpDateTime.NanoSeconds ) ); nType = CUSTOM_TYPE_DATETIME; } @@ -1866,7 +1866,7 @@ Sequence< beans::PropertyValue > CustomPropertiesWindow::GetCustomProperties() c { Date aTmpDate = pLine->m_aDateField.GetDate(); Time aTmpTime = pLine->m_aTimeField.GetTime(); - util::DateTime aDateTime(aTmpTime.Get100Sec(), aTmpTime.GetSec(), aTmpTime.GetMin(), aTmpTime.GetHour(), + util::DateTime aDateTime(aTmpTime.GetNanoSec(), aTmpTime.GetSec(), aTmpTime.GetMin(), aTmpTime.GetHour(), aTmpDate.GetDay(), aTmpDate.GetMonth(), aTmpDate.GetYear() ); aPropertiesSeq[i].Value <<= aDateTime; } diff --git a/sfx2/source/dialog/versdlg.cxx b/sfx2/source/dialog/versdlg.cxx index 25db61b2d705..41ade0fe68d1 100644 --- a/sfx2/source/dialog/versdlg.cxx +++ b/sfx2/source/dialog/versdlg.cxx @@ -105,7 +105,7 @@ SfxVersionTableDtor::SfxVersionTableDtor( const uno::Sequence < util::RevisionTa pInfo->aAuthor = rInfo[n].Author; Date aDate ( rInfo[n].TimeStamp.Day, rInfo[n].TimeStamp.Month, rInfo[n].TimeStamp.Year ); - Time aTime ( rInfo[n].TimeStamp.Hours, rInfo[n].TimeStamp.Minutes, rInfo[n].TimeStamp.Seconds, rInfo[n].TimeStamp.HundredthSeconds ); + Time aTime ( rInfo[n].TimeStamp.Hours, rInfo[n].TimeStamp.Minutes, rInfo[n].TimeStamp.Seconds, rInfo[n].TimeStamp.NanoSeconds ); pInfo->aCreationDate = DateTime( aDate, aTime ); aTableList.push_back( pInfo ); diff --git a/sfx2/source/doc/SfxDocumentMetaData.cxx b/sfx2/source/doc/SfxDocumentMetaData.cxx index e4a03d0be849..d83b1950dc7d 100644 --- a/sfx2/source/doc/SfxDocumentMetaData.cxx +++ b/sfx2/source/doc/SfxDocumentMetaData.cxx @@ -412,7 +412,7 @@ bool operator== (const css::util::DateTime &i_rLeft, && i_rLeft.Hours == i_rRight.Hours && i_rLeft.Minutes == i_rRight.Minutes && i_rLeft.Seconds == i_rRight.Seconds - && i_rLeft.HundredthSeconds == i_rRight.HundredthSeconds; + && i_rLeft.NanoSeconds == i_rRight.NanoSeconds; } // NB: keep these two arrays in sync! @@ -633,7 +633,7 @@ OUString SAL_CALL durationToText(sal_Int32 i_value) throw () ud.Hours = static_cast<sal_Int16>((i_value % (24 * 3600)) / 3600); ud.Minutes = static_cast<sal_Int16>((i_value % 3600) / 60); ud.Seconds = static_cast<sal_Int16>(i_value % 60); - ud.MilliSeconds = 0; + ud.NanoSeconds = 0; return durationToText(ud); } @@ -967,7 +967,7 @@ propsToStrings(css::uno::Reference<css::beans::XPropertySet> const & i_xPropSet) ud.Hours = ut.Hours; ud.Minutes = ut.Minutes; ud.Seconds = ut.Seconds; - ud.MilliSeconds = 10 * ut.HundredthSeconds; + ud.NanoSeconds = ut.NanoSeconds; values.push_back(durationToText(ud)); as.push_back(std::make_pair(vt, OUString("time"))); @@ -1837,7 +1837,7 @@ SfxDocumentMetaData::resetUserData(const OUString & the_value) bool bModified( false ); bModified |= setMetaText("meta:initial-creator", the_value); ::DateTime now( ::DateTime::SYSTEM ); - css::util::DateTime uDT(now.Get100Sec(), now.GetSec(), now.GetMin(), + css::util::DateTime uDT(now.GetNanoSec(), now.GetSec(), now.GetMin(), now.GetHour(), now.GetDay(), now.GetMonth(), now.GetYear()); bModified |= setMetaText("meta:creation-date", dateTimeToText(uDT)); bModified |= setMetaText("dc:creator", OUString()); diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx index 7f3a31e5213a..86883d10e6b4 100644 --- a/sfx2/source/doc/objcont.cxx +++ b/sfx2/source/doc/objcont.cxx @@ -100,8 +100,8 @@ bool operator> (const util::DateTime& i_rLeft, const util::DateTime& i_rRight) if ( i_rLeft.Seconds != i_rRight.Seconds ) return i_rLeft.Seconds > i_rRight.Seconds; - if ( i_rLeft.HundredthSeconds != i_rRight.HundredthSeconds ) - return i_rLeft.HundredthSeconds > i_rRight.HundredthSeconds; + if ( i_rLeft.NanoSeconds != i_rRight.NanoSeconds ) + return i_rLeft.NanoSeconds > i_rRight.NanoSeconds; return sal_False; } @@ -202,7 +202,7 @@ void SfxObjectShell::UpdateDocInfoForSave() // update ModificationAuthor, revision and editing time ::DateTime now( ::DateTime::SYSTEM ); xDocProps->setModificationDate( util::DateTime( - now.Get100Sec(), now.GetSec(), now.GetMin(), + now.GetNanoSec(), now.GetSec(), now.GetMin(), now.GetHour(), now.GetDay(), now.GetMonth(), now.GetYear() ) ); xDocProps->setModifiedBy( aUserName ); @@ -833,7 +833,7 @@ void SfxObjectShell::ResetFromTemplate( const String& rTemplateName, const Strin ::DateTime now( ::DateTime::SYSTEM ); xDocProps->setTemplateDate( util::DateTime( - now.Get100Sec(), now.GetSec(), now.GetMin(), + now.GetNanoSec(), now.GetSec(), now.GetMin(), now.GetHour(), now.GetDay(), now.GetMonth(), now.GetYear() ) ); diff --git a/sfx2/source/doc/oleprops.cxx b/sfx2/source/doc/oleprops.cxx index 48f19c324a16..6ecc27a05e84 100644 --- a/sfx2/source/doc/oleprops.cxx +++ b/sfx2/source/doc/oleprops.cxx @@ -52,7 +52,7 @@ bool operator==(const util::DateTime &i_rLeft, const util::DateTime &i_rRight) && i_rLeft.Hours == i_rRight.Hours && i_rLeft.Minutes == i_rRight.Minutes && i_rLeft.Seconds == i_rRight.Seconds - && i_rLeft.HundredthSeconds == i_rRight.HundredthSeconds; + && i_rLeft.NanoSeconds == i_rRight.NanoSeconds; } static @@ -586,7 +586,7 @@ void SfxOleFileTimeProperty::ImplLoad( SvStream& rStrm ) maDateTime.Hours = aDateTime.GetHour(); maDateTime.Minutes = aDateTime.GetMin(); maDateTime.Seconds = aDateTime.GetSec(); - maDateTime.HundredthSeconds = aDateTime.Get100Sec(); + maDateTime.NanoSeconds = aDateTime.GetNanoSec(); } void SfxOleFileTimeProperty::ImplSave( SvStream& rStrm ) @@ -600,7 +600,7 @@ void SfxOleFileTimeProperty::ImplSave( SvStream& rStrm ) static_cast< sal_uIntPtr >( maDateTime.Hours ), static_cast< sal_uIntPtr >( maDateTime.Minutes ), static_cast< sal_uIntPtr >( maDateTime.Seconds ), - static_cast< sal_uIntPtr >( maDateTime.HundredthSeconds ) ) ); + static_cast< sal_uIntPtr >( maDateTime.NanoSeconds ) ) ); // invalid time stamp is not converted to UTC // heuristic to detect editing durations (which we assume to be < 1 year): // check only the year, not the entire date diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx index f518bae40dbb..3c2fff7a146f 100644 --- a/sfx2/source/view/viewprn.cxx +++ b/sfx2/source/view/viewprn.cxx @@ -317,7 +317,7 @@ void SfxPrinterController::jobStarted() ::DateTime now( ::DateTime::SYSTEM ); xDocProps->setPrintDate( util::DateTime( - now.Get100Sec(), now.GetSec(), now.GetMin(), now.GetHour(), + now.GetNanoSec(), now.GetSec(), now.GetMin(), now.GetHour(), now.GetDay(), now.GetMonth(), now.GetYear() ) ); SFX_APP()->NotifyEvent( SfxEventHint(SFX_EVENT_PRINTDOC, GlobalEventConfig::GetEventName( STR_EVENT_PRINTDOC ), mpObjectShell ) ); diff --git a/svl/source/items/dateitem.cxx b/svl/source/items/dateitem.cxx index 5dc90ada2fbd..706d373c5371 100644 --- a/svl/source/items/dateitem.cxx +++ b/svl/source/items/dateitem.cxx @@ -163,7 +163,7 @@ bool SfxDateTimeItem::PutValue( const com::sun::star::uno::Any& rVal, Time( aValue.Hours, aValue.Minutes, aValue.Seconds, - aValue.HundredthSeconds ) ); + aValue.NanoSeconds ) ); return true; } @@ -177,7 +177,7 @@ bool SfxDateTimeItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const { nMemberId &= ~CONVERT_TWIPS; - com::sun::star::util::DateTime aValue( aDateTime.Get100Sec(), + com::sun::star::util::DateTime aValue( aDateTime.GetNanoSec(), aDateTime.GetSec(), aDateTime.GetMin(), aDateTime.GetHour(), diff --git a/svl/source/misc/fstathelper.cxx b/svl/source/misc/fstathelper.cxx index f1692f256e18..498d57bb91c7 100644 --- a/svl/source/misc/fstathelper.cxx +++ b/svl/source/misc/fstathelper.cxx @@ -49,7 +49,7 @@ sal_Bool FStatHelper::GetModifiedDateTimeOfFile( const OUString& rURL, *pDate = Date( pDT->Day, pDT->Month, pDT->Year ); if( pTime ) *pTime = Time( pDT->Hours, pDT->Minutes, - pDT->Seconds, pDT->HundredthSeconds ); + pDT->Seconds, pDT->NanoSeconds ); } } catch(...) diff --git a/svtools/source/contnr/DocumentInfoPreview.cxx b/svtools/source/contnr/DocumentInfoPreview.cxx index 3380c14a43e5..2a546077986b 100644 --- a/svtools/source/contnr/DocumentInfoPreview.cxx +++ b/svtools/source/contnr/DocumentInfoPreview.cxx @@ -150,7 +150,7 @@ void ODocumentInfoPreview::insertDateTime( DateTime aToolsDT( Date(value.Day, value.Month, value.Year), Time( - value.Hours, value.Minutes, value.Seconds, value.HundredthSeconds)); + value.Hours, value.Minutes, value.Seconds, value.NanoSeconds)); if (aToolsDT.IsValidAndGregorian()) { const LocaleDataWrapper& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() ); OUStringBuffer buf(rLocaleWrapper.getDate(aToolsDT)); diff --git a/svtools/source/contnr/contentenumeration.cxx b/svtools/source/contnr/contentenumeration.cxx index 7e62273bf460..decda28f110d 100644 --- a/svtools/source/contnr/contentenumeration.cxx +++ b/svtools/source/contnr/contentenumeration.cxx @@ -57,7 +57,7 @@ namespace svt #define CONVERT_DATETIME( aUnoDT, aToolsDT ) \ aToolsDT = ::DateTime( Date( aUnoDT.Day, aUnoDT.Month, aUnoDT.Year ), \ - Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.HundredthSeconds ) ); + Time( aUnoDT.Hours, aUnoDT.Minutes, aUnoDT.Seconds, aUnoDT.NanoSeconds ) ); using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; diff --git a/svtools/source/misc/templatefoldercache.cxx b/svtools/source/misc/templatefoldercache.cxx index d8103cfcd050..aa2bade43ffd 100644 --- a/svtools/source/misc/templatefoldercache.cxx +++ b/svtools/source/misc/templatefoldercache.cxx @@ -57,7 +57,7 @@ namespace svt //--------------------------------------------------------------------- SvStream& operator << ( SvStream& _rStorage, const util::DateTime& _rDate ) { - _rStorage << _rDate.HundredthSeconds; + _rStorage << _rDate.NanoSeconds; _rStorage << _rDate.Seconds; _rStorage << _rDate.Minutes; _rStorage << _rDate.Hours; @@ -71,7 +71,7 @@ namespace svt //--------------------------------------------------------------------- SvStream& operator >> ( SvStream& _rStorage, util::DateTime& _rDate ) { - _rStorage >> _rDate.HundredthSeconds; + _rStorage >> _rDate.NanoSeconds; _rStorage >> _rDate.Seconds; _rStorage >> _rDate.Minutes; _rStorage >> _rDate.Hours; @@ -85,7 +85,7 @@ namespace svt //--------------------------------------------------------------------- sal_Bool operator == ( const util::DateTime& _rLHS, const util::DateTime& _rRHS ) { - return _rLHS.HundredthSeconds == _rRHS.HundredthSeconds + return _rLHS.NanoSeconds == _rRHS.NanoSeconds && _rLHS.Seconds == _rRHS.Seconds && _rLHS.Minutes == _rRHS.Minutes && _rLHS.Hours == _rRHS.Hours @@ -123,7 +123,7 @@ namespace svt private: inline void implResetDate( ) { - m_aLastModified.HundredthSeconds = m_aLastModified.Seconds = m_aLastModified.Minutes = m_aLastModified.Hours = 0; + m_aLastModified.NanoSeconds = m_aLastModified.Seconds = m_aLastModified.Minutes = m_aLastModified.Hours = 0; m_aLastModified.Day = m_aLastModified.Month = m_aLastModified.Year = 0; } diff --git a/svtools/source/svhtml/parhtml.cxx b/svtools/source/svhtml/parhtml.cxx index dd1b60d9658b..d8d5080fcf92 100644 --- a/svtools/source/svhtml/parhtml.cxx +++ b/svtools/source/svhtml/parhtml.cxx @@ -2170,7 +2170,7 @@ bool HTMLParser::ParseMetaOptionsImpl( Date aDate( (sal_uLong)aContent.GetToken(0).ToInt32() ); Time aTime( (sal_uLong)aContent.GetToken(1).ToInt32() ); DateTime aDateTime( aDate, aTime ); - ::util::DateTime uDT(aDateTime.Get100Sec(), + ::util::DateTime uDT(aDateTime.GetNanoSec(), aDateTime.GetSec(), aDateTime.GetMin(), aDateTime.GetHour(), aDateTime.GetDay(), aDateTime.GetMonth(), aDateTime.GetYear()); diff --git a/svtools/source/table/cellvalueconversion.cxx b/svtools/source/table/cellvalueconversion.cxx index 0f26ab2811fb..d753b5293090 100644 --- a/svtools/source/table/cellvalueconversion.cxx +++ b/svtools/source/table/cellvalueconversion.cxx @@ -239,7 +239,7 @@ namespace svt // time part returnValue += lcl_convertTimeToDays( - aDateTimeValue.Hours, aDateTimeValue.Minutes, aDateTimeValue.Seconds, aDateTimeValue.HundredthSeconds ); + aDateTimeValue.Hours, aDateTimeValue.Minutes, aDateTimeValue.Seconds, aDateTimeValue.NanoSeconds ); // done return returnValue; @@ -300,7 +300,7 @@ namespace svt // convert returnValue += lcl_convertTimeToDays( - aTimeValue.Hours, aTimeValue.Minutes, aTimeValue.Seconds, aTimeValue.HundredthSeconds ); + aTimeValue.Hours, aTimeValue.Minutes, aTimeValue.Seconds, aTimeValue.NanoSeconds ); // done return returnValue; diff --git a/svx/source/fmcomp/gridcell.cxx b/svx/source/fmcomp/gridcell.cxx index 1022fbfebc3c..29a4ef641731 100644 --- a/svx/source/fmcomp/gridcell.cxx +++ b/svx/source/fmcomp/gridcell.cxx @@ -2398,7 +2398,7 @@ namespace _rField.SetText( sTime ); else { - _rField.SetTime( ::Time( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.HundredthSeconds ) ); + _rField.SetTime( ::Time( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.NanoSeconds ) ); sTime = _rField.GetText(); } } diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx index fc896f3c4a06..fc5ad2ba4203 100644 --- a/sw/source/core/doc/doccomp.cxx +++ b/sw/source/core/doc/doccomp.cxx @@ -1654,7 +1654,7 @@ void SwCompareData::SetRedlinesToDoc( sal_Bool bUseDocInfo ) ? xDocProps->getCreationDate() : xDocProps->getModificationDate() ); Date d(uDT.Day, uDT.Month, uDT.Year); - Time t(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time t(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); DateTime aDT(d,t); if( aTmp.Len() ) diff --git a/sw/source/core/doc/docglbl.cxx b/sw/source/core/doc/docglbl.cxx index 5c0eb98509cc..58dd0333b0b2 100644 --- a/sw/source/core/doc/docglbl.cxx +++ b/sw/source/core/doc/docglbl.cxx @@ -272,7 +272,7 @@ bool SwDoc::SplitDoc( sal_uInt16 eDocType, const String& rPath, bool bOutline, c OSL_ENSURE(xDocProps.is(), "Doc has no DocumentProperties"); // the GlobalDoc is the template xDocProps->setTemplateName(aEmptyStr); - ::util::DateTime uDT(aTmplDate.Get100Sec(), + ::util::DateTime uDT(aTmplDate.GetNanoSec(), aTmplDate.GetSec(), aTmplDate.GetMin(), aTmplDate.GetHour(), aTmplDate.GetDay(), aTmplDate.GetMonth(), aTmplDate.GetYear()); diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx index 5c2cdf00bfad..6f3e18b222ec 100644 --- a/sw/source/core/doc/docredln.cxx +++ b/sw/source/core/doc/docredln.cxx @@ -2994,7 +2994,7 @@ SwRedlineData::SwRedlineData( RedlineType_t eT, sal_uInt16 nAut ) eType( eT ), nAuthor( nAut ), nSeqNo( 0 ) { aStamp.SetSec( 0 ); - aStamp.Set100Sec( 0 ); + aStamp.SetNanoSec( 0 ); } SwRedlineData::SwRedlineData( const SwRedlineData& rCpy, sal_Bool bCpyNext ) diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx index 5783b506aae9..eee6211c0328 100644 --- a/sw/source/core/fields/docufld.cxx +++ b/sw/source/core/fields/docufld.cxx @@ -973,7 +973,7 @@ String SwDocInfoFieldType::Expand( sal_uInt16 nSub, sal_uInt32 nFormat, String aName( xDocProps->getAuthor() ); util::DateTime uDT( xDocProps->getCreationDate() ); Date aD(uDT.Day, uDT.Month, uDT.Year); - Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); DateTime aDate(aD,aT); if( nSub == DI_CREATE ) ; // das wars schon!! @@ -982,7 +982,7 @@ String SwDocInfoFieldType::Expand( sal_uInt16 nSub, sal_uInt32 nFormat, aName = xDocProps->getModifiedBy(); uDT = xDocProps->getModificationDate(); Date bD(uDT.Day, uDT.Month, uDT.Year); - Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); DateTime bDate(bD,bT); aDate = bDate; } @@ -991,7 +991,7 @@ String SwDocInfoFieldType::Expand( sal_uInt16 nSub, sal_uInt32 nFormat, aName = xDocProps->getPrintedBy(); uDT = xDocProps->getPrintDate(); Date bD(uDT.Day, uDT.Month, uDT.Year); - Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); DateTime bDate(bD,bT); aDate = bDate; } @@ -1068,8 +1068,8 @@ SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const template<class T> static double lcl_TimeToDouble( const T& rTime ) { - const double fMilliSecondsPerDay = 86400000.0; - return ((rTime.Hours*3600000)+(rTime.Minutes*60000)+(rTime.Seconds*1000)+(rTime.HundredthSeconds*10)) / fMilliSecondsPerDay; + const double fNanoSecondsPerDay = 86400000000000.0; + return ((rTime.Hours*3600000)+(rTime.Minutes*60000)+(rTime.Seconds*1000)+(rTime.NanoSeconds)) / fNanoSecondsPerDay; } template<class D> @@ -1904,7 +1904,7 @@ bool SwPostItField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const case FIELD_PROP_DATE_TIME: { util::DateTime DateTimeValue; - DateTimeValue.HundredthSeconds = aDateTime.Get100Sec(); + DateTimeValue.NanoSeconds = aDateTime.GetNanoSec(); DateTimeValue.Seconds = aDateTime.GetSec(); DateTimeValue.Minutes = aDateTime.GetMin(); DateTimeValue.Hours = aDateTime.GetHour(); @@ -1957,7 +1957,7 @@ bool SwPostItField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) util::DateTime aDateTimeValue; if(!(rAny >>= aDateTimeValue)) return sal_False; - aDateTime.Set100Sec(aDateTimeValue.HundredthSeconds); + aDateTime.SetNanoSec(aDateTimeValue.NanoSeconds); aDateTime.SetSec(aDateTimeValue.Seconds); aDateTime.SetMin(aDateTimeValue.Minutes); aDateTime.SetHour(aDateTimeValue.Hours); diff --git a/sw/source/core/fields/flddat.cxx b/sw/source/core/fields/flddat.cxx index ddd92926b508..6f9076c6b6fa 100644 --- a/sw/source/core/fields/flddat.cxx +++ b/sw/source/core/fields/flddat.cxx @@ -194,7 +194,7 @@ bool SwDateTimeField::QueryValue( uno::Any& rVal, sal_uInt16 nWhichId ) const DateTime aDateTime(GetDate(), GetTime()); util::DateTime DateTimeValue; - DateTimeValue.HundredthSeconds = aDateTime.Get100Sec(); + DateTimeValue.NanoSeconds = aDateTime.GetNanoSec(); DateTimeValue.Seconds = aDateTime.GetSec(); DateTimeValue.Minutes = aDateTime.GetMin(); DateTimeValue.Hours = aDateTime.GetHour(); @@ -239,7 +239,7 @@ bool SwDateTimeField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId ) if(!(rVal >>= aDateTimeValue)) return false; DateTime aDateTime( DateTime::EMPTY ); - aDateTime.Set100Sec(aDateTimeValue.HundredthSeconds); + aDateTime.SetNanoSec(aDateTimeValue.NanoSeconds); aDateTime.SetSec(aDateTimeValue.Seconds); aDateTime.SetMin(aDateTimeValue.Minutes); aDateTime.SetHour(aDateTimeValue.Hours); diff --git a/sw/source/core/unocore/swunohelper.cxx b/sw/source/core/unocore/swunohelper.cxx index 98d076bac5e1..63e9027e9854 100644 --- a/sw/source/core/unocore/swunohelper.cxx +++ b/sw/source/core/unocore/swunohelper.cxx @@ -240,7 +240,7 @@ bool UCB_GetFileListOfFolder( const String& rURL, ::Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds, - aStamp.HundredthSeconds )); + aStamp.NanoSeconds )); pDateTimeList->push_back( pDateTime ); } } diff --git a/sw/source/core/unocore/unoredline.cxx b/sw/source/core/unocore/unoredline.cxx index d891e66c28fc..7870c3886200 100644 --- a/sw/source/core/unocore/unoredline.cxx +++ b/sw/source/core/unocore/unoredline.cxx @@ -204,7 +204,7 @@ static util::DateTime lcl_DateTimeToUno(const DateTime& rDT) aRetDT.Hours = rDT.GetHour(); aRetDT.Minutes = rDT.GetMin(); aRetDT.Seconds = rDT.GetSec(); - aRetDT.HundredthSeconds = rDT.Get100Sec(); + aRetDT.NanoSeconds = rDT.GetNanoSec(); return aRetDT; } diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index a62370fdb3af..de440b04ea30 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -284,15 +284,15 @@ static void WriteDop( WW8Export& rWrt ) { ::util::DateTime uDT = xDocProps->getCreationDate(); Date aD(uDT.Day, uDT.Month, uDT.Year); - Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); rDop.dttmCreated = sw::ms::DateTime2DTTM(DateTime(aD,aT)); uDT = xDocProps->getModificationDate(); Date aD2(uDT.Day, uDT.Month, uDT.Year); - Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time aT2(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); rDop.dttmRevised = sw::ms::DateTime2DTTM(DateTime(aD2,aT2)); uDT = xDocProps->getPrintDate(); Date aD3(uDT.Day, uDT.Month, uDT.Year); - Time aT3(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); + Time aT3(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds); rDop.dttmLastPrint = sw::ms::DateTime2DTTM(DateTime(aD3,aT3)); } diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index cc00d10f45cc..627f5aa6448f 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -1487,7 +1487,7 @@ void SwWW8ImplReader::ImportDop() { DateTime aLastPrinted( msfilter::util::DTTM2DateTime(pWDop->dttmLastPrint)); - ::util::DateTime uDT(aLastPrinted.Get100Sec(), + ::util::DateTime uDT(aLastPrinted.GetNanoSec(), aLastPrinted.GetSec(), aLastPrinted.GetMin(), aLastPrinted.GetHour(), aLastPrinted.GetDay(), aLastPrinted.GetMonth(), aLastPrinted.GetYear()); diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx index b2abe8fa8642..00a59c7baa68 100644 --- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx +++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx @@ -723,7 +723,7 @@ SwRedlineData* XMLRedlineImportHelper::ConvertRedline( aDT.SetHour( pRedlineInfo->aDateTime.Hours ); aDT.SetMin( pRedlineInfo->aDateTime.Minutes ); aDT.SetSec( pRedlineInfo->aDateTime.Seconds ); - aDT.Set100Sec( pRedlineInfo->aDateTime.HundredthSeconds ); + aDT.SetNanoSec( pRedlineInfo->aDateTime.NanoSeconds ); // 3) recursively convert next redline // ( check presence and sanity of hierarchical redline info ) diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk index 9ea13e7e290e..5491b8c90e91 100644 --- a/tools/Library_tl.mk +++ b/tools/Library_tl.mk @@ -97,6 +97,12 @@ $(eval $(call gb_Library_use_externals,tl,\ zlib \ )) +ifeq ($(OS),LINUX) +$(eval $(call gb_Library_add_libs,tl,\ + -lrt \ +)) +endif + ifeq ($(OS),WNT) $(eval $(call gb_Library_use_system_win32_libs,tl,\ diff --git a/tools/inc/tools/datetime.hxx b/tools/inc/tools/datetime.hxx index 0a799343145e..1de0f3d6432c 100644 --- a/tools/inc/tools/datetime.hxx +++ b/tools/inc/tools/datetime.hxx @@ -50,11 +50,11 @@ public: sal_Bool IsBetween( const DateTime& rFrom, const DateTime& rTo ) const; - sal_Bool IsEqualIgnore100Sec( const DateTime& rDateTime ) const + sal_Bool IsEqualIgnoreNanoSec( const DateTime& rDateTime ) const { if ( Date::operator!=( rDateTime ) ) return sal_False; - return Time::IsEqualIgnore100Sec( rDateTime ); + return Time::IsEqualIgnoreNanoSec( rDateTime ); } sal_Bool operator ==( const DateTime& rDateTime ) const diff --git a/tools/inc/tools/time.hxx b/tools/inc/tools/time.hxx index fe585103bb2e..ce6eb42ebe88 100644 --- a/tools/inc/tools/time.hxx +++ b/tools/inc/tools/time.hxx @@ -33,7 +33,7 @@ class ResId; class TOOLS_DLLPUBLIC SAL_WARN_UNUSED Time { private: - sal_Int32 nTime; + sal_Int64 nTime; public: enum TimeInitSystem @@ -46,38 +46,54 @@ public: { EMPTY }; + static const sal_Int64 hourPerDay = 24; + static const sal_Int64 minutePerHour = 60; + static const sal_Int64 secondPerMinute = 60; + static const sal_Int64 nanoSecPerSec = 1000000000; + static const sal_Int64 nanoSecPerMinute = nanoSecPerSec * secondPerMinute; + static const sal_Int64 nanoSecPerHour = nanoSecPerSec * secondPerMinute * minutePerHour; + static const sal_Int64 nanoSecPerDay = nanoSecPerSec * secondPerMinute * minutePerHour * hourPerDay; + static const sal_Int64 secondPerHour = secondPerMinute * minutePerHour; + static const sal_Int64 secondPerDay = secondPerMinute * minutePerHour * hourPerDay; + static const sal_Int64 minutePerDay = minutePerHour * hourPerDay; + static const sal_Int64 nanoPerMicro = 1000; + static const sal_Int64 nanoPerMilli = 1000000; + static const sal_Int64 nanoPerCenti = 10000000; Time( TimeInitEmpty ) { nTime = 0; } Time( TimeInitSystem ); Time( const ResId & rResId ); - Time( sal_Int32 _nTime ) { Time::nTime = _nTime; } + Time( sal_Int64 _nTime ) { Time::nTime = _nTime; } Time( const Time& rTime ); Time( sal_uIntPtr nHour, sal_uIntPtr nMin, - sal_uIntPtr nSec = 0, sal_uIntPtr n100Sec = 0 ); + sal_uIntPtr nSec = 0, sal_uIntPtr nNanoSec = 0 ); - void SetTime( sal_Int32 nNewTime ) { nTime = nNewTime; } - sal_Int32 GetTime() const { return nTime; } + void SetTime( sal_Int64 nNewTime ) { nTime = nNewTime; } + sal_Int64 GetTime() const { return nTime; } void SetHour( sal_uInt16 nNewHour ); void SetMin( sal_uInt16 nNewMin ); void SetSec( sal_uInt16 nNewSec ); - void Set100Sec( sal_uInt16 nNew100Sec ); + void SetNanoSec( sal_uInt32 nNewNanoSec ); sal_uInt16 GetHour() const - { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1; - return (sal_uInt16)(nTempTime / 1000000); } + { sal_uInt64 nTempTime = (nTime >= 0) ? nTime : -nTime; + return static_cast<sal_uInt16>(nTempTime / 10000000000000); } sal_uInt16 GetMin() const - { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1; - return (sal_uInt16)((nTempTime / 10000) % 100); } + { sal_uInt64 nTempTime = (nTime >= 0) ? nTime : -nTime; + return static_cast<sal_uInt16>((nTempTime / 100000000000) % 100); } sal_uInt16 GetSec() const - { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1; - return (sal_uInt16)((nTempTime / 100) % 100); } - sal_uInt16 Get100Sec() const - { sal_uIntPtr nTempTime = (nTime >= 0) ? nTime : nTime*-1; - return (sal_uInt16)(nTempTime % 100); } + { sal_uInt64 nTempTime = (nTime >= 0) ? nTime : -nTime; + return static_cast<sal_uInt16>((nTempTime / 1000000000) % 100); } + sal_uInt32 GetNanoSec() const + { sal_uInt64 nTempTime = (nTime >= 0) ? nTime : -nTime; + return static_cast<sal_uInt32>( nTempTime % 1000000000); } + // TODO: consider removing GetMSFromTime and MakeTimeFromMS? sal_Int32 GetMSFromTime() const; void MakeTimeFromMS( sal_Int32 nMS ); + sal_Int64 GetNSFromTime() const; + void MakeTimeFromNS( sal_Int64 nNS ); /// 12 hours == 0.5 days double GetTimeInDays() const; @@ -85,7 +101,7 @@ public: sal_Bool IsBetween( const Time& rFrom, const Time& rTo ) const { return ((nTime >= rFrom.nTime) && (nTime <= rTo.nTime)); } - sal_Bool IsEqualIgnore100Sec( const Time& rTime ) const; + sal_Bool IsEqualIgnoreNanoSec( const Time& rTime ) const; sal_Bool operator ==( const Time& rTime ) const { return (nTime == rTime.nTime); } @@ -108,7 +124,7 @@ public: Time& operator =( const Time& rTime ); Time operator -() const - { return Time( nTime * -1 ); } + { return Time( -nTime ); } Time& operator +=( const Time& rTime ); Time& operator -=( const Time& rTime ); TOOLS_DLLPUBLIC friend Time operator +( const Time& rTime1, const Time& rTime2 ); diff --git a/tools/source/datetime/datetime.cxx b/tools/source/datetime/datetime.cxx index 4027d16fce97..1bf612730bb0 100644 --- a/tools/source/datetime/datetime.cxx +++ b/tools/source/datetime/datetime.cxx @@ -181,8 +181,8 @@ DateTime& DateTime::operator +=( double fTimeInDays ) if ( fFrac ) { Time aTime(0); // default ctor calls system time, we don't need that - fFrac *= 24UL * 60 * 60 * 1000; // time expressed in milliseconds - aTime.MakeTimeFromMS( long(fFrac) ); // method handles negative ms + fFrac *= ::Time::nanoSecPerDay; // time expressed in nanoseconds + aTime.MakeTimeFromNS( static_cast<sal_Int64>(fFrac) ); // method handles negative ns operator+=( aTime ); } return *this; @@ -198,11 +198,11 @@ DateTime operator +( const DateTime& rDateTime, double fTimeInDays ) double operator -( const DateTime& rDateTime1, const DateTime& rDateTime2 ) { long nDays = (const Date&) rDateTime1 - (const Date&) rDateTime2; - long nTime = rDateTime1.GetMSFromTime() - rDateTime2.GetMSFromTime(); + sal_Int64 nTime = rDateTime1.GetNSFromTime() - rDateTime2.GetNSFromTime(); if ( nTime ) { double fTime = double(nTime); - fTime /= 24UL * 60 * 60 * 1000; // convert from milliseconds to fraction + fTime /= ::Time::nanoSecPerDay; // convert from nanoseconds to fraction if ( nDays < 0 && fTime > 0.0 ) fTime = 1.0 - fTime; return double(nDays) + fTime; @@ -223,10 +223,7 @@ void DateTime::GetWin32FileDateTime( sal_uInt32 & rLower, sal_uInt32 & rUpper ) sal_Int64 aTime = a100nPerDay * nDays + - a100nPerSecond * ( - sal_Int64( GetSec() ) + - 60 * sal_Int64( GetMin() ) + - 60 * 60 * sal_Int64( GetHour() ) ); + GetNSFromTime()/100; rLower = sal_uInt32( aTime % SAL_CONST_UINT64( 0x100000000 ) ); rUpper = sal_uInt32( aTime / SAL_CONST_UINT64( 0x100000000 ) ); @@ -263,8 +260,9 @@ DateTime DateTime::CreateFromWin32FileDateTime( const sal_uInt32 & rLower, const (sal_uInt16)( nDays + 1 ), nMonths, sal::static_int_cast< sal_uInt16 >(nYears + 1601) ); Time _aTime( sal_uIntPtr( ( aTime / ( a100nPerSecond * 60 * 60 ) ) % sal_Int64( 24 ) ), - sal_uIntPtr( ( aTime / ( a100nPerSecond * 60 ) ) % sal_Int64( 60 ) ), - sal_uIntPtr( ( aTime / ( a100nPerSecond ) ) % sal_Int64( 60 ) ) ); + sal_uIntPtr( ( aTime / ( a100nPerSecond * 60 ) ) % sal_Int64( 60 ) ), + sal_uIntPtr( ( aTime / ( a100nPerSecond ) ) % sal_Int64( 60 ) ), + (aTime % a100nPerSecond) * 100 ); return DateTime( _aDate, _aTime ); } diff --git a/tools/source/datetime/ttime.cxx b/tools/source/datetime/ttime.cxx index b32c09078e40..2841bb119173 100644 --- a/tools/source/datetime/ttime.cxx +++ b/tools/source/datetime/ttime.cxx @@ -27,46 +27,61 @@ #endif #include <time.h> +#ifdef __MACH__ +#include <mach/clock.h> +#include <mach/mach.h> +#endif #include <tools/time.hxx> +#include <osl/diagnose.h> + #if defined(SOLARIS) && defined(__GNUC__) extern long altzone; #endif -static sal_Int32 TimeToSec100( const Time& rTime ) -{ - short nSign = (rTime.GetTime() >= 0) ? +1 : -1; - sal_Int32 nHour = rTime.GetHour(); - sal_Int32 nMin = rTime.GetMin(); - sal_Int32 nSec = rTime.GetSec(); - sal_Int32 n100Sec = rTime.Get100Sec(); +namespace { -// Due to interal compiler error in MSC a little bit more complicated: -// return (n100Sec + (nSec*100) + (nMin*60*100) + (nHour*60*60*100) * nSign); + const sal_Int64 secMask = 1000000000; + const sal_Int64 minMask = 100000000000; + const sal_Int64 hourMask = 10000000000000; - sal_Int32 nRet = n100Sec; - nRet += nSec*100; - nRet += nMin*60*100; - nRet += nHour*60*60*100; + const sal_Int64 nanoSecInSec = 1000000000; + const sal_Int16 secInMin = 60; + const sal_Int16 minInHour = 60; - return (nRet * nSign); -} + sal_Int64 TimeToNanoSec( const Time& rTime ) + { + short nSign = (rTime.GetTime() >= 0) ? +1 : -1; + sal_Int32 nHour = rTime.GetHour(); + sal_Int32 nMin = rTime.GetMin(); + sal_Int32 nSec = rTime.GetSec(); + sal_Int32 nNanoSec = rTime.GetNanoSec(); + + sal_Int64 nRet = nNanoSec; + nRet += nSec * nanoSecInSec; + nRet += nMin * secInMin * nanoSecInSec; + nRet += nHour * minInHour * secInMin * nanoSecInSec; + + return (nRet * nSign); + } -static Time Sec100ToTime( sal_Int32 nSec100 ) -{ - short nSign; - if ( nSec100 < 0 ) + Time NanoSecToTime( sal_Int64 nNanoSec ) { - nSec100 *= -1; - nSign = -1; + short nSign; + if ( nNanoSec < 0 ) + { + nNanoSec *= -1; + nSign = -1; + } + else + nSign = 1; + + Time aTime( 0, 0, 0, nNanoSec ); + aTime.SetTime( aTime.GetTime() * nSign ); + return aTime; } - else - nSign = 1; - Time aTime( 0, 0, 0, nSec100 ); - aTime.SetTime( aTime.GetTime() * nSign ); - return aTime; -} +} // anonymous namespace Time::Time( TimeInitSystem ) { @@ -75,27 +90,47 @@ Time::Time( TimeInitSystem ) GetLocalTime( &aDateTime ); // construct time - nTime = (((sal_Int32)aDateTime.wHour)*1000000) + - (((sal_Int32)aDateTime.wMinute)*10000) + - (((sal_Int32)aDateTime.wSecond)*100) + - ((sal_Int32)aDateTime.wMilliseconds/10); + nTime = aDateTime.wHour * hourMask + + aDateTime.wMinute * minMask + + aDateTime.wSecond * secMask + + aDateTime.wMilliseconds * 1000000; #else - time_t nTmpTime; - struct tm aTime; - // determine time - nTmpTime = time( 0 ); + struct timespec tsTime; +#if defined( __MACH__ ) + // OS X does not have clock_gettime, use clock_get_time + clock_serv_t cclock; + mach_timespec_t mts; + host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); + clock_get_time(cclock, &mts); + mach_port_deallocate(mach_task_self(), cclock); + tsTime.tv_sec = mts.tv_sec; + tsTime.tv_nsec = mts.tv_nsec; +#else + // CLOCK_REALTIME should be supported + // on any modern Unix, but be extra cautious + if (clock_gettime(CLOCK_REALTIME, &tsTime) != 0) + { + struct timeval tvTime; + OSL_VERIFY( gettimeofday(&tvTime, NULL) != 0 ); + tsTime.tv_sec = tvTime.tv_sec; + tsTime.tv_nsec = tvTime.tv_usec * 1000; + } +#endif // __MACH__ // construct time + struct tm aTime; + time_t nTmpTime = tsTime.tv_sec; if ( localtime_r( &nTmpTime, &aTime ) ) { - nTime = (((sal_Int32)aTime.tm_hour)*1000000) + - (((sal_Int32)aTime.tm_min)*10000) + - (((sal_Int32)aTime.tm_sec)*100); + nTime = aTime.tm_hour * hourMask + + aTime.tm_min * minMask + + aTime.tm_sec * secMask + + tsTime.tv_nsec; } else nTime = 0; -#endif +#endif // WNT } Time::Time( const Time& rTime ) @@ -103,43 +138,52 @@ Time::Time( const Time& rTime ) nTime = rTime.nTime; } -Time::Time( sal_uIntPtr nHour, sal_uIntPtr nMin, sal_uIntPtr nSec, sal_uIntPtr n100Sec ) +Time::Time( sal_uIntPtr nHour, sal_uIntPtr nMin, sal_uIntPtr nSec, sal_uIntPtr nNanoSec ) { // normalize time - nSec += n100Sec / 100; - n100Sec = n100Sec % 100; - nMin += nSec / 60; - nSec = nSec % 60; - nHour += nMin / 60; - nMin = nMin % 60; + nSec += nNanoSec / nanoSecInSec; + nNanoSec %= nanoSecInSec; + nMin += nSec / secInMin; + nSec %= secInMin; + nHour += nMin / minInHour; + nMin %= minInHour; // construct time - nTime = (sal_Int32)(n100Sec + (nSec*100) + (nMin*10000) + (nHour*1000000)); + nTime = nNanoSec + + nSec * secMask + + nMin * minMask + + nHour * hourMask; } void Time::SetHour( sal_uInt16 nNewHour ) { - short nSign = (nTime >= 0) ? +1 : -1; + short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nMin = GetMin(); sal_Int32 nSec = GetSec(); - sal_Int32 n100Sec = Get100Sec(); + sal_Int32 nNanoSec = GetNanoSec(); - nTime = (n100Sec + (nSec*100) + (nMin*10000) + - (((sal_Int32)nNewHour)*1000000)) * nSign; + nTime = nSign * + ( nNanoSec + + nSec * secMask + + nMin * minMask + + nNewHour * hourMask ); } void Time::SetMin( sal_uInt16 nNewMin ) { - short nSign = (nTime >= 0) ? +1 : -1; + short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nHour = GetHour(); sal_Int32 nSec = GetSec(); - sal_Int32 n100Sec = Get100Sec(); + sal_Int32 nNanoSec = GetNanoSec(); // no overflow - nNewMin = nNewMin % 60; + nNewMin = nNewMin % minInHour; - nTime = (n100Sec + (nSec*100) + (((sal_Int32)nNewMin)*10000) + - (nHour*1000000)) * nSign; + nTime = nSign * + ( nNanoSec + + nSec * secMask + + nNewMin * minMask + + nHour * hourMask ); } void Time::SetSec( sal_uInt16 nNewSec ) @@ -147,16 +191,19 @@ void Time::SetSec( sal_uInt16 nNewSec ) short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nHour = GetHour(); sal_Int32 nMin = GetMin(); - sal_Int32 n100Sec = Get100Sec(); + sal_Int32 nNanoSec = GetNanoSec(); // no overflow - nNewSec = nNewSec % 60; + nNewSec = nNewSec % secInMin; - nTime = (n100Sec + (((sal_Int32)nNewSec)*100) + (nMin*10000) + - (nHour*1000000)) * nSign; + nTime = nSign * + ( nNanoSec + + nNewSec * secMask + + nMin * minMask + + nHour * hourMask ); } -void Time::Set100Sec( sal_uInt16 nNew100Sec ) +void Time::SetNanoSec( sal_uInt32 nNewNanoSec ) { short nSign = (nTime >= 0) ? +1 : -1; sal_Int32 nHour = GetHour(); @@ -164,10 +211,44 @@ void Time::Set100Sec( sal_uInt16 nNew100Sec ) sal_Int32 nSec = GetSec(); // no overflow - nNew100Sec = nNew100Sec % 100; + nNewNanoSec = nNewNanoSec % nanoSecInSec; + + nTime = nSign * + ( nNewNanoSec + + nSec * secMask + + nMin * minMask + + nHour * hourMask ); +} + +sal_Int64 Time::GetNSFromTime() const +{ + short nSign = (nTime >= 0) ? +1 : -1; + sal_Int32 nHour = GetHour(); + sal_Int32 nMin = GetMin(); + sal_Int32 nSec = GetSec(); + sal_Int32 nNanoSec = GetNanoSec(); + + return nSign * + ( nNanoSec + + nSec * nanoSecInSec + + nMin * (secInMin * nanoSecInSec) + + nHour * (minInHour * secInMin * nanoSecInSec) ); +} + +void Time::MakeTimeFromNS( sal_Int64 nNS ) +{ + short nSign; + if ( nNS < 0 ) + { + nNS *= -1; + nSign = -1; + } + else + nSign = 1; - nTime = (((sal_Int32)nNew100Sec) + (nSec*100) + (nMin*10000) + - (nHour*1000000)) * nSign; + // avoid overflow when sal_uIntPtr is 32 bits + Time aTime( 0, 0, nNS/nanoSecInSec, nNS % nanoSecInSec ); + SetTime( aTime.GetTime() * nSign ); } sal_Int32 Time::GetMSFromTime() const @@ -176,9 +257,13 @@ sal_Int32 Time::GetMSFromTime() const sal_Int32 nHour = GetHour(); sal_Int32 nMin = GetMin(); sal_Int32 nSec = GetSec(); - sal_Int32 n100Sec = Get100Sec(); + sal_Int32 nNanoSec = GetNanoSec(); - return (((nHour*3600000)+(nMin*60000)+(nSec*1000)+(n100Sec*10))*nSign); + return nSign * + ( nNanoSec/1000000 + + nSec * 1000 + + nMin * 60000 + + nHour * 360000 ); } void Time::MakeTimeFromMS( sal_Int32 nMS ) @@ -192,7 +277,8 @@ void Time::MakeTimeFromMS( sal_Int32 nMS ) else nSign = 1; - Time aTime( 0, 0, 0, nMS/10 ); + // avoid overflow when sal_uIntPtr is 32 bits + Time aTime( 0, 0, nMS/1000, (nMS % 1000) * 1000000 ); SetTime( aTime.GetTime() * nSign ); } @@ -202,9 +288,9 @@ double Time::GetTimeInDays() const double nHour = GetHour(); double nMin = GetMin(); double nSec = GetSec(); - double n100Sec = Get100Sec(); + double nNanoSec = GetNanoSec(); - return (nHour+(nMin/60)+(nSec/(60*60))+(n100Sec/(60*60*100))) / 24 * nSign; + return (nHour + (nMin / 60) + (nSec / (minInHour * secInMin)) + (nNanoSec / (minInHour * secInMin * nanoSecInSec))) / 24 * nSign; } Time& Time::operator =( const Time& rTime ) @@ -215,34 +301,34 @@ Time& Time::operator =( const Time& rTime ) Time& Time::operator +=( const Time& rTime ) { - nTime = Sec100ToTime( TimeToSec100( *this ) + - TimeToSec100( rTime ) ).GetTime(); + nTime = NanoSecToTime( TimeToNanoSec( *this ) + + TimeToNanoSec( rTime ) ).GetTime(); return *this; } Time& Time::operator -=( const Time& rTime ) { - nTime = Sec100ToTime( TimeToSec100( *this ) - - TimeToSec100( rTime ) ).GetTime(); + nTime = NanoSecToTime( TimeToNanoSec( *this ) - + TimeToNanoSec( rTime ) ).GetTime(); return *this; } Time operator +( const Time& rTime1, const Time& rTime2 ) { - return Sec100ToTime( TimeToSec100( rTime1 ) + - TimeToSec100( rTime2 ) ); + return NanoSecToTime( TimeToNanoSec( rTime1 ) + + TimeToNanoSec( rTime2 ) ); } Time operator -( const Time& rTime1, const Time& rTime2 ) { - return Sec100ToTime( TimeToSec100( rTime1 ) - - TimeToSec100( rTime2 ) ); + return NanoSecToTime( TimeToNanoSec( rTime1 ) - + TimeToNanoSec( rTime2 ) ); } -sal_Bool Time::IsEqualIgnore100Sec( const Time& rTime ) const +sal_Bool Time::IsEqualIgnoreNanoSec( const Time& rTime ) const { - sal_Int32 n1 = (nTime < 0 ? -Get100Sec() : Get100Sec() ); - sal_Int32 n2 = (rTime.nTime < 0 ? -rTime.Get100Sec() : rTime.Get100Sec() ); + sal_Int32 n1 = (nTime < 0 ? -static_cast<sal_Int32>(GetNanoSec()) : GetNanoSec() ); + sal_Int32 n2 = (rTime.nTime < 0 ? -static_cast<sal_Int32>(rTime.GetNanoSec()) : rTime.GetNanoSec() ); return (nTime - n1) == (rTime.nTime - n2); } diff --git a/tools/source/inet/inetmsg.cxx b/tools/source/inet/inetmsg.cxx index 914d59caca82..120a1db0a32c 100644 --- a/tools/source/inet/inetmsg.cxx +++ b/tools/source/inet/inetmsg.cxx @@ -303,7 +303,7 @@ bool INetRFC822Message::ParseDateField ( rDateTime.SetHour (ParseNumber (aDateField, nIndex)); nIndex++; rDateTime.SetMin (ParseNumber (aDateField, nIndex)); nIndex++; rDateTime.SetSec (ParseNumber (aDateField, nIndex)); nIndex++; - rDateTime.Set100Sec (0); + rDateTime.SetNanoSec (0); sal_uInt16 nYear = ParseNumber (aDateField, nIndex); if (nYear < 100) nYear += 1900; @@ -324,7 +324,7 @@ bool INetRFC822Message::ParseDateField ( rDateTime.SetHour (ParseNumber (aDateField, nIndex)); nIndex++; rDateTime.SetMin (ParseNumber (aDateField, nIndex)); nIndex++; rDateTime.SetSec (ParseNumber (aDateField, nIndex)); nIndex++; - rDateTime.Set100Sec (0); + rDateTime.SetNanoSec (0); if ((aDateField[nIndex] == '+') || (aDateField[nIndex] == '-') ) @@ -338,7 +338,7 @@ bool INetRFC822Message::ParseDateField ( aDiff.SetHour (nOffset / 100); aDiff.SetMin (nOffset % 100); aDiff.SetSec (0); - aDiff.Set100Sec (0); + aDiff.SetNanoSec (0); if (bEast) rDateTime -= aDiff; diff --git a/tools/source/rc/rc.cxx b/tools/source/rc/rc.cxx index 87ec7667d4eb..7ebdae058461 100644 --- a/tools/source/rc/rc.cxx +++ b/tools/source/rc/rc.cxx @@ -54,7 +54,10 @@ Time::Time( const ResId& rResId ) if ( 0x04 & nObjMask ) SetSec( (sal_uInt16)pResMgr->ReadShort() ); if ( 0x08 & nObjMask ) - Set100Sec( (sal_uInt16)pResMgr->ReadShort() ); + // TODO: when we change the place that writes this binary resource format to match: + // SetNanoSec( pResMgr->ReadLong() ); + // In the meantime: + SetNanoSec( pResMgr->ReadShort() * ::Time::nanoPerCenti ); } Date::Date( const ResId& rResId ) : nDate(0) diff --git a/ucb/source/sorter/sortresult.cxx b/ucb/source/sorter/sortresult.cxx index 089946a4f7de..4e72d45932ed 100644 --- a/ucb/source/sorter/sortresult.cxx +++ b/ucb/source/sorter/sortresult.cxx @@ -1133,8 +1133,8 @@ long SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne, if ( !nTmp ) { nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds; if ( !nTmp ) - nTmp = (sal_Int32) aTwo.HundredthSeconds - - (sal_Int32) aOne.HundredthSeconds; + nTmp = (sal_Int32) aTwo.NanoSeconds + - (sal_Int32) aOne.NanoSeconds; }} if ( nTmp < 0 ) @@ -1168,8 +1168,8 @@ long SortedResultSet::CompareImpl( Reference < XResultSet > xResultOne, if ( !nTmp ) { nTmp = (sal_Int32) aTwo.Seconds - (sal_Int32) aOne.Seconds; if ( !nTmp ) - nTmp = (sal_Int32) aTwo.HundredthSeconds - - (sal_Int32) aOne.HundredthSeconds; + nTmp = (sal_Int32) aTwo.NanoSeconds + - (sal_Int32) aOne.NanoSeconds; }}}}} if ( nTmp < 0 ) diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx index a32fdbbb11d3..3675a706c5e1 100644 --- a/ucb/source/ucp/cmis/cmis_content.cxx +++ b/ucb/source/ucp/cmis/cmis_content.cxx @@ -85,11 +85,13 @@ namespace unoTime.Minutes = boostTime.time_of_day().minutes(); unoTime.Seconds = boostTime.time_of_day().seconds(); - long total_milli = boostTime.time_of_day().total_milliseconds( ); - long milli = total_milli - boostTime.time_of_day().total_seconds( ); - long hundredthSeconds = milli / 10; + // TODO FIXME maybe we should compile with BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG + // to actually get nanosecond precision in boostTime? + // use this way rather than total_nanos to avoid overflows with 32-bit long + const long ticks = boostTime.time_of_day().fractional_seconds(); + long nanoSeconds = ticks * ( 1000000000 / boost::posix_time::time_duration::ticks_per_second()); - unoTime.HundredthSeconds = hundredthSeconds; + unoTime.NanoSeconds = nanoSeconds; return unoTime; } diff --git a/ucb/source/ucp/file/shell.cxx b/ucb/source/ucp/file/shell.cxx index 23221fcb3968..ec7bce87f18a 100644 --- a/ucb/source/ucp/file/shell.cxx +++ b/ucb/source/ucp/file/shell.cxx @@ -2431,7 +2431,7 @@ shell::commit( const shell::ContentMap::iterator& it, osl_getDateTimeFromTimeValue( &myLocalTime, &myDateTime ); util::DateTime aDateTime; - aDateTime.HundredthSeconds = (unsigned short)(myDateTime.NanoSeconds / 10000000); + aDateTime.NanoSeconds = myDateTime.NanoSeconds; aDateTime.Seconds = myDateTime.Seconds; aDateTime.Minutes = myDateTime.Minutes; aDateTime.Hours = myDateTime.Hours; diff --git a/ucb/source/ucp/ftp/ftpdirp.cxx b/ucb/source/ucp/ftp/ftpdirp.cxx index 2e6bece679a9..87f38b88a569 100644 --- a/ucb/source/ucp/ftp/ftpdirp.cxx +++ b/ucb/source/ucp/ftp/ftpdirp.cxx @@ -828,7 +828,7 @@ sal_Bool FTPDirectoryParser::parseVMS ( /* * Parse <minute> part and set entry time's minutes, - * seconds (0), and 1/100 seconds (0). + * seconds (0), and nanoseconds (0). */ if (*p < '0' || *p > '5') return sal_False; @@ -840,7 +840,7 @@ sal_Bool FTPDirectoryParser::parseVMS ( nMinute = 10 * nMinute + (*p++ - '0'); rEntry.m_aDate.SetMin(nMinute); rEntry.m_aDate.SetSec(0); - rEntry.m_aDate.Set100Sec(0); + rEntry.m_aDate.SetNanoSec(0); // Skip <rest> part: if (*p && (*p != '\t' && *p != ' ')) @@ -1202,7 +1202,7 @@ sal_Bool FTPDirectoryParser::parseUNIX_isTime ( rDateTime.SetHour (nHour); rDateTime.SetMin (nMin); rDateTime.SetSec (0); - rDateTime.Set100Sec (0); + rDateTime.SetNanoSec (0); // Date aCurDate; // if (rDateTime.GetMonth() > aCurDate.GetMonth()) diff --git a/ucb/source/ucp/ftp/ftpdirp.hxx b/ucb/source/ucp/ftp/ftpdirp.hxx index 68dc11879c0b..f8e04b9f138f 100644 --- a/ucb/source/ucp/ftp/ftpdirp.hxx +++ b/ucb/source/ucp/ftp/ftpdirp.hxx @@ -41,14 +41,14 @@ namespace ftp { struct DateTime : public com::sun::star::util::DateTime { - DateTime(const sal_uInt16& hundredthSeconds, + DateTime(const sal_uInt32& nanoSeconds, const sal_uInt16& seconds, const sal_uInt16& minutes, const sal_uInt16& hours, const sal_uInt16& day, const sal_uInt16& month, const sal_uInt16& year) SAL_THROW(()) - : com::sun::star::util::DateTime(hundredthSeconds, + : com::sun::star::util::DateTime(nanoSeconds, seconds, minutes, hours, @@ -60,11 +60,11 @@ namespace ftp { void SetMonth(sal_uInt16 month) { Month = month; } void SetDay(sal_uInt16 day) { Day = day; } // Only zero allowed and used for time-argument - void SetTime(sal_uInt16) { Hours = Minutes = Seconds = HundredthSeconds = 0; } + void SetTime(sal_uInt16) { Hours = Minutes = Seconds = NanoSeconds = 0; } void SetHour(sal_uInt16 hours) { Hours = hours; } void SetMin(sal_uInt16 minutes) { Minutes = minutes; } void SetSec(sal_uInt16 seconds) { Seconds = seconds; } - void Set100Sec(sal_uInt16 hundredthSec) { HundredthSeconds = hundredthSec; } + void SetNanoSec(sal_uInt32 nanoSec) { NanoSeconds = nanoSec; } sal_uInt16 GetMonth(void) { return Month; } }; diff --git a/unotools/inc/unotools/datetime.hxx b/unotools/inc/unotools/datetime.hxx index 042fa737642b..dfc0ab139825 100644 --- a/unotools/inc/unotools/datetime.hxx +++ b/unotools/inc/unotools/datetime.hxx @@ -44,6 +44,12 @@ namespace utl UNOTOOLS_DLLPUBLIC void typeConvert(const DateTime& _rDateTime, starutil::DateTime& _rOut); UNOTOOLS_DLLPUBLIC void typeConvert(const starutil::DateTime& _rDateTime, DateTime& _rOut); + UNOTOOLS_DLLPUBLIC ::rtl::OUString toISO8601(const starutil::DateTime& _rDateTime); + UNOTOOLS_DLLPUBLIC ::rtl::OUString toISO8601(const starutil::Time& _rTime); + UNOTOOLS_DLLPUBLIC bool ISO8601parseDateTime(const ::rtl::OUString &i_rIn, starutil::DateTime& o_rDateTime); + UNOTOOLS_DLLPUBLIC bool ISO8601parseDate(const ::rtl::OUString &i_rIn, starutil::Date& o_rDate); + UNOTOOLS_DLLPUBLIC bool ISO8601parseTime(const ::rtl::OUString &i_rIn, starutil::Time& o_Time); + //......................................................................... } // namespace utl //......................................................................... diff --git a/unotools/source/i18n/localedatawrapper.cxx b/unotools/source/i18n/localedatawrapper.cxx index 45f24499c70e..493485444dc9 100644 --- a/unotools/source/i18n/localedatawrapper.cxx +++ b/unotools/source/i18n/localedatawrapper.cxx @@ -1140,7 +1140,7 @@ static sal_Unicode* ImplAddUNum( sal_Unicode* pBuf, sal_uInt64 nNumber, int nMin } -static sal_Unicode* ImplAdd2UNum( sal_Unicode* pBuf, sal_uInt16 nNumber, int bLeading ) +static sal_Unicode* ImplAdd2UNum( sal_Unicode* pBuf, sal_uInt16 nNumber, bool bLeading ) { DBG_ASSERT( nNumber < 100, "ImplAdd2UNum() - Number >= 100" ); @@ -1166,6 +1166,24 @@ static sal_Unicode* ImplAdd2UNum( sal_Unicode* pBuf, sal_uInt16 nNumber, int bLe return pBuf; } +static sal_Unicode* ImplAdd9UNum( sal_Unicode* pBuf, sal_uInt32 nNumber, bool bLeading ) +{ + DBG_ASSERT( nNumber < 1000000000, "ImplAdd2UNum() - Number >= 1000000000" ); + + std::ostringstream ostr; + if (bLeading) + { + ostr.fill('0'); + ostr.width(9); + } + ostr << nNumber; + for(const char *pAB=ostr.str().c_str(); *pAB != '\0'; ++pAB, ++pBuf) + { + *pBuf = *pAB; + } + + return pBuf; +} inline sal_Unicode* ImplAddString( sal_Unicode* pBuf, const OUString& rStr ) { @@ -1375,16 +1393,16 @@ OUString LocaleDataWrapper::getTime( const Time& rTime, sal_Bool bSec, sal_Bool pBuf = ImplAdd2UNum( pBuf, nHour, sal_True /* IsTimeLeadingZero() */ ); pBuf = ImplAddString( pBuf, getTimeSep() ); - pBuf = ImplAdd2UNum( pBuf, rTime.GetMin(), sal_True ); + pBuf = ImplAdd2UNum( pBuf, rTime.GetMin(), true ); if ( bSec ) { pBuf = ImplAddString( pBuf, getTimeSep() ); - pBuf = ImplAdd2UNum( pBuf, rTime.GetSec(), sal_True ); + pBuf = ImplAdd2UNum( pBuf, rTime.GetSec(), true ); if ( b100Sec ) { pBuf = ImplAddString( pBuf, getTime100SecSep() ); - pBuf = ImplAdd2UNum( pBuf, rTime.Get100Sec(), sal_True ); + pBuf = ImplAdd9UNum( pBuf, rTime.GetNanoSec(), true ); } } @@ -1473,16 +1491,16 @@ OUString LocaleDataWrapper::getDuration( const Time& rTime, sal_Bool bSec, sal_B else pBuf = ImplAddUNum( pBuf, rTime.GetHour() ); pBuf = ImplAddString( pBuf, getTimeSep() ); - pBuf = ImplAdd2UNum( pBuf, rTime.GetMin(), sal_True ); + pBuf = ImplAdd2UNum( pBuf, rTime.GetMin(), true ); if ( bSec ) { pBuf = ImplAddString( pBuf, getTimeSep() ); - pBuf = ImplAdd2UNum( pBuf, rTime.GetSec(), sal_True ); + pBuf = ImplAdd2UNum( pBuf, rTime.GetSec(), true ); if ( b100Sec ) { pBuf = ImplAddString( pBuf, getTime100SecSep() ); - pBuf = ImplAdd2UNum( pBuf, rTime.Get100Sec(), sal_True ); + pBuf = ImplAdd9UNum( pBuf, rTime.GetNanoSec(), true ); } } diff --git a/unotools/source/misc/datetime.cxx b/unotools/source/misc/datetime.cxx index ff4062523dee..cbfb1694e33d 100644 --- a/unotools/source/misc/datetime.cxx +++ b/unotools/source/misc/datetime.cxx @@ -21,6 +21,147 @@ #include <tools/date.hxx> #include <tools/time.hxx> #include <tools/datetime.hxx> +#include <stdexcept> +#include <rtl/ustrbuf.hxx> +#include <rtl/math.hxx> + +namespace +{ + sal_Int32 impl_pow(sal_Int32 x, sal_Int32 y) + { + if (y == 1) + return x; + if ( y % 2 == 0) + { + return impl_pow(x*x, y/2); + } + else + { + return x * impl_pow(x*x, y/2); + } + } + // computes x^y + sal_Int32 pow(sal_Int32 x, sal_Int32 y) + { + if (y < 0) + throw std::invalid_argument("negative power is not defined in integers"); + if (y == 0) + return 1; + return impl_pow(x, y); + } + + /** convert string to number with optional min and max values */ + template <typename T> + bool convertNumber( T& rValue, + const OUString& rString, + T /*nMin*/ = -1, T /*nMax*/ = -1) + { + sal_Bool bNeg = sal_False; + rValue = 0; + + sal_Int32 nPos = 0L; + sal_Int32 nLen = rString.getLength(); + + // skip white space + while( nPos < nLen && sal_Unicode(' ') == rString[nPos] ) + nPos++; + + if( nPos < nLen && sal_Unicode('-') == rString[nPos] ) + { + bNeg = sal_True; + nPos++; + } + + // get number + while( nPos < nLen && + sal_Unicode('0') <= rString[nPos] && + sal_Unicode('9') >= rString[nPos] ) + { + // TODO: check overflow! + rValue *= 10; + rValue += (rString[nPos] - sal_Unicode('0')); + nPos++; + } + + if( bNeg ) + rValue *= -1; + + return nPos == nLen; + } + + // although the standard calls for fixed-length (zero-padded) tokens + // (in their integer part), we are here liberal and allow shorter tokens + // (when there are separators, else it is ambiguous). + // Note that: + // the token separator is OPTIONAL + // empty string is a valid token! (to recognise hh or hhmm or hh:mm formats) + // returns: success / failure + // in case of failure, no reference argument is changed + // arguments: + // i_str: string to extract token from + // index: index in i_str where to start tokenizing + // after return, start of *next* token (if any) + // if this was the last token, then the value is UNDEFINED + // o_strInt: output; integer part of token + // o_bFraction: output; was there a fractional part? + // o_strFrac: output; fractional part of token + bool impl_getISO8601TimeToken(const OUString &i_str, sal_Int32 &nPos, OUString &resInt, bool &bFraction, OUString &resFrac) + { + bFraction = false; + // all tokens are of length 2 + const sal_Int32 nEndPos = nPos + 2; + const sal_Unicode c0 = '0'; + const sal_Unicode c9 = '9'; + const sal_Unicode sep = ':'; + for (;nPos < nEndPos && nPos < i_str.getLength(); ++nPos) + { + const sal_Unicode c = i_str[nPos]; + if (c == sep) + return true; + if (c < c0 || c > c9) + return false; + resInt += OUString(c); + } + if (nPos == i_str.getLength() || i_str[nPos] == sep) + return true; + if (i_str[nPos] == ',' || i_str[nPos] == '.') + { + bFraction = true; + ++nPos; + for (; nPos < i_str.getLength(); ++nPos) + { + const sal_Unicode c = i_str[nPos]; + if (c == sep) + // fractional part allowed only in *last* token + return false; + if (c < c0 || c > c9) + return false; + resFrac += OUString(c); + } + OSL_ENSURE(nPos == i_str.getLength(), "impl_getISO8601TimeToken internal error; expected to be at end of string"); + return true; + } + else + return false; + } + inline bool getISO8601TimeToken(const OUString &i_str, sal_Int32 &io_index, OUString &o_strInt, bool &o_bFraction, OUString &o_strFrac) + { + OUString resInt; + OUString resFrac; + bool bFraction = false; + sal_Int32 index = io_index; + if(!impl_getISO8601TimeToken(i_str, index, resInt, bFraction, resFrac)) + return false; + else + { + io_index = index+1; + o_strInt = resInt; + o_strFrac = resFrac; + o_bFraction = bFraction; + return true; + } + } +} //......................................................................... namespace utl @@ -48,21 +189,22 @@ void typeConvert(const DateTime& _rDateTime, starutil::DateTime& _rOut) _rOut.Hours = _rDateTime.GetHour(); _rOut.Minutes = _rDateTime.GetMin(); _rOut.Seconds = _rDateTime.GetSec(); - _rOut.HundredthSeconds = _rDateTime.Get100Sec(); + _rOut.NanoSeconds = _rDateTime.GetNanoSec(); } //------------------------------------------------------------------ void typeConvert(const starutil::DateTime& _rDateTime, DateTime& _rOut) { Date aDate(_rDateTime.Day, _rDateTime.Month, _rDateTime.Year); - Time aTime(_rDateTime.Hours, _rDateTime.Minutes, _rDateTime.Seconds, _rDateTime.HundredthSeconds); + Time aTime(_rDateTime.Hours, _rDateTime.Minutes, _rDateTime.Seconds, _rDateTime.NanoSeconds); _rOut = DateTime(aDate, aTime); } +// FIXME: these operators should be.... in toplevel namespace? announced in the .hxx file? //------------------------------------------------------------------------- -sal_Bool operator ==(const starutil::DateTime& _rLeft, const starutil::DateTime& _rRight) +bool operator ==(const starutil::DateTime& _rLeft, const starutil::DateTime& _rRight) { - return ( _rLeft.HundredthSeconds == _rRight.HundredthSeconds) && + return ( _rLeft.NanoSeconds == _rRight.NanoSeconds) && ( _rLeft.Seconds == _rRight.Seconds) && ( _rLeft.Minutes == _rRight.Minutes) && ( _rLeft.Hours == _rRight.Hours) && @@ -72,7 +214,7 @@ sal_Bool operator ==(const starutil::DateTime& _rLeft, const starutil::DateTi } //------------------------------------------------------------------------- -sal_Bool operator ==(const starutil::Date& _rLeft, const starutil::Date& _rRight) +bool operator ==(const starutil::Date& _rLeft, const starutil::Date& _rRight) { return ( _rLeft.Day == _rRight.Day) && ( _rLeft.Month == _rRight.Month) && @@ -80,14 +222,292 @@ sal_Bool operator ==(const starutil::Date& _rLeft, const starutil::Date& _rRi } //------------------------------------------------------------------------- -sal_Bool operator ==(const starutil::Time& _rLeft, const starutil::Time& _rRight) +bool operator ==(const starutil::Time& _rLeft, const starutil::Time& _rRight) { - return ( _rLeft.HundredthSeconds == _rRight.HundredthSeconds) && + return ( _rLeft.NanoSeconds == _rRight.NanoSeconds) && ( _rLeft.Seconds == _rRight.Seconds) && ( _rLeft.Minutes == _rRight.Minutes) && ( _rLeft.Hours == _rRight.Hours) ; } +OUString toISO8601(const starutil::DateTime& rDateTime) +{ + OUStringBuffer rBuffer; + rBuffer.append((sal_Int32) rDateTime.Year); + rBuffer.append('-'); + if( rDateTime.Month < 10 ) + rBuffer.append('0'); + rBuffer.append((sal_Int32) rDateTime.Month); + rBuffer.append('-'); + if( rDateTime.Day < 10 ) + rBuffer.append('0'); + rBuffer.append((sal_Int32) rDateTime.Day); + + if( rDateTime.NanoSeconds != 0 || + rDateTime.Seconds != 0 || + rDateTime.Minutes != 0 || + rDateTime.Hours != 0 ) + { + rBuffer.append('T'); + if( rDateTime.Hours < 10 ) + rBuffer.append('0'); + rBuffer.append((sal_Int32) rDateTime.Hours); + rBuffer.append(':'); + if( rDateTime.Minutes < 10 ) + rBuffer.append('0'); + rBuffer.append((sal_Int32) rDateTime.Minutes); + rBuffer.append(':'); + if( rDateTime.Seconds < 10 ) + rBuffer.append('0'); + rBuffer.append((sal_Int32) rDateTime.Seconds); + if ( rDateTime.NanoSeconds > 0) + { + OSL_ENSURE(rDateTime.NanoSeconds < 1000000000,"NanoSeconds cannot be more than 999 999 999"); + rBuffer.append(','); + std::ostringstream ostr; + ostr.fill('0'); + ostr.width(9); + ostr << rDateTime.NanoSeconds; + rBuffer.append(OUString::createFromAscii(ostr.str().c_str())); + } + } + return rBuffer.makeStringAndClear(); +} + +OUString toISO8601(const starutil::Time& rTime) +{ + OUStringBuffer rBuffer; + if( rTime.Hours < 10 ) + rBuffer.append('0'); + rBuffer.append((sal_Int32) rTime.Hours); + rBuffer.append(':'); + if( rTime.Minutes < 10 ) + rBuffer.append('0'); + rBuffer.append((sal_Int32) rTime.Minutes); + rBuffer.append(':'); + if( rTime.Seconds < 10 ) + rBuffer.append('0'); + rBuffer.append((sal_Int32) rTime.Seconds); + if ( rTime.NanoSeconds > 0) + { + OSL_ENSURE(rTime.NanoSeconds < 1000000000,"NanoSeconds cannot be more than 999 999 999"); + rBuffer.append(','); + std::ostringstream ostr; + ostr.fill('0'); + ostr.width(9); + ostr << rTime.NanoSeconds; + rBuffer.append(OUString::createFromAscii(ostr.str().c_str())); + } + return rBuffer.makeStringAndClear(); +} + +/** convert ISO8601 DateTime String to util::DateTime */ +bool ISO8601parseDateTime(const OUString &rString, starutil::DateTime& rDateTime) +{ + bool bSuccess = true; + + rtl::OUString aDateStr, aTimeStr; + starutil::Date aDate; + starutil::Time aTime; + sal_Int32 nPos = rString.indexOf( (sal_Unicode) 'T' ); + if ( nPos >= 0 ) + { + aDateStr = rString.copy( 0, nPos ); + aTimeStr = rString.copy( nPos + 1 ); + } + else + aDateStr = rString; // no separator: only date part + + bSuccess = ISO8601parseDate(aDateStr, aDate); + + if ( bSuccess && !aTimeStr.isEmpty() ) // time is optional + { + bSuccess = ISO8601parseTime(aTimeStr, aTime); + } + + if (bSuccess) + { + rDateTime = starutil::DateTime(aTime.NanoSeconds, aTime.Seconds, aTime.Minutes, aTime.Hours, + aDate.Day, aDate.Month, aDate.Year); + } + + return bSuccess; +} + +/** convert ISO8601 Date String to util::Date */ +// TODO: supports only calendar dates YYYY-MM-DD +// MISSING: calendar dates YYYYMMDD YYYY-MM +// year, week date, ordinal date +bool ISO8601parseDate(const OUString &aDateStr, starutil::Date& rDate) +{ + bool bSuccess = true; + + sal_Int32 nYear = 1899; + sal_Int32 nMonth = 12; + sal_Int32 nDay = 30; + + const sal_Unicode* pStr = aDateStr.getStr(); + sal_Int32 nDateTokens = 1; + while ( *pStr ) + { + if ( *pStr == '-' ) + nDateTokens++; + pStr++; + } + if ( nDateTokens > 3 || aDateStr.isEmpty() ) + bSuccess = false; + else + { + sal_Int32 n = 0; + if ( !convertNumber<sal_Int32>( nYear, aDateStr.getToken( 0, '-', n ), 0, 9999 ) ) + bSuccess = false; + if ( nDateTokens >= 2 ) + if ( !convertNumber<sal_Int32>( nMonth, aDateStr.getToken( 0, '-', n ), 0, 12 ) ) + bSuccess = false; + if ( nDateTokens >= 3 ) + if ( !convertNumber<sal_Int32>( nDay, aDateStr.getToken( 0, '-', n ), 0, 31 ) ) + bSuccess = false; + } + + if (bSuccess) + { + rDate.Year = (sal_uInt16)nYear; + rDate.Month = (sal_uInt16)nMonth; + rDate.Day = (sal_uInt16)nDay; + } + + return bSuccess; +} + +/** convert ISO8601 Time String to util::Time */ +bool ISO8601parseTime(const OUString &aTimeStr, starutil::Time& rTime) +{ + bool bSuccess = true; + + sal_Int32 nHour = 0; + sal_Int32 nMin = 0; + sal_Int32 nSec = 0; + sal_Int32 nNanoSec = 0; + + sal_Int32 n = 0; + OUString tokInt; + OUString tokFrac; + bool bFrac; + // hours + if (bSuccess && (bSuccess = getISO8601TimeToken(aTimeStr, n, tokInt, bFrac, tokFrac))) + { + if ( bFrac && n < aTimeStr.getLength()) + // junk after ISO time + bSuccess = false; + else if ( (bSuccess = convertNumber<sal_Int32>( nHour, tokInt, 0, 23 )) ) + { + if (bFrac) + { + sal_Int64 fracNumerator; + if ( (bSuccess = convertNumber(fracNumerator, tokFrac)) ) + { + double frac = static_cast<double>(fracNumerator) / static_cast<double>(pow(10, tokFrac.getLength())); + // minutes + OSL_ENSURE(frac < 1 && frac >= 0, "ISO8601parse internal error frac hours (of hours) not between 0 and 1"); + frac *= 60; + nMin = floor(frac); + frac -= nMin; + // seconds + OSL_ENSURE(frac < 1 && frac >= 0, "ISO8601parse internal error frac minutes (of hours) not between 0 and 1"); + frac *= 60; + nSec = floor(frac); + frac -= nSec; + // nanoseconds + OSL_ENSURE(frac < 1 && frac >= 0, "ISO8601parse internal error frac seconds (of hours) not between 0 and 1"); + frac *= 1000000000; + nNanoSec = ::rtl::math::round(frac); + } + goto end; + } + } + } + // minutes + if (bSuccess && (bSuccess = getISO8601TimeToken(aTimeStr, n, tokInt, bFrac, tokFrac))) + { + if ( bFrac && n < aTimeStr.getLength()) + // junk after ISO time + bSuccess = false; + else if ( (bSuccess = convertNumber<sal_Int32>( nMin, tokInt, 0, 59 )) ) + { + if (bFrac) + { + sal_Int64 fracNumerator; + if ( (bSuccess = convertNumber(fracNumerator, tokFrac)) ) + { + double frac = static_cast<double>(fracNumerator) / static_cast<double>(pow(10, tokFrac.getLength())); + // seconds + OSL_ENSURE(frac < 1 && frac >= 0, "ISO8601parse internal error frac minutes (of minutes) not between 0 and 1"); + frac *= 60; + nSec = floor(frac); + frac -= nSec; + // nanoseconds + OSL_ENSURE(frac < 1 && frac >= 0, "ISO8601parse internal error frac seconds (of minutes) not between 0 and 1"); + frac *= 1000000000; + nNanoSec = ::rtl::math::round(frac); + } + goto end; + } + } + } + // seconds + if (bSuccess && (bSuccess = getISO8601TimeToken(aTimeStr, n, tokInt, bFrac, tokFrac))) + { + if ( bFrac && n < aTimeStr.getLength()) + // junk after ISO time + bSuccess = false; + // max 60 for leap seconds + else if ( (bSuccess = convertNumber<sal_Int32>( nSec, tokInt, 0, 60 )) ) + { + if (bFrac) + { + sal_Int64 fracNumerator; + if ( (bSuccess = convertNumber(fracNumerator, tokFrac)) ) + { + double frac = static_cast<double>(fracNumerator) / static_cast<double>(pow(10, tokFrac.getLength())); + // nanoseconds + OSL_ENSURE(frac < 1 && frac >= 0, "ISO8601parse internal error frac seconds (of seconds) not between 0 and 1"); + frac *= 1000000000; + nNanoSec = ::rtl::math::round(frac); + } + goto end; + } + } + } + + end: + if (bSuccess) + { + // normalise time + const int secondsOverFlow = (nSec == 60) ? 61 : 60; + if (nNanoSec == 1000000000) + { + nNanoSec = 0; + ++nSec; + } + if(nSec == secondsOverFlow) + { + nSec = 0; + ++nMin; + } + if(nMin == 60) + { + nMin = 0; + ++nHour; + } + + rTime.Hours = (sal_uInt16)nHour; + rTime.Minutes = (sal_uInt16)nMin; + rTime.Seconds = (sal_uInt16)nSec; + rTime.NanoSeconds = nNanoSec; + } + + return bSuccess; +} //......................................................................... } // namespace utl //......................................................................... diff --git a/unotools/source/ucbhelper/ucbhelper.cxx b/unotools/source/ucbhelper/ucbhelper.cxx index 9dbd82a9b1cb..82b869f1940b 100644 --- a/unotools/source/ucbhelper/ucbhelper.cxx +++ b/unotools/source/ucbhelper/ucbhelper.cxx @@ -121,7 +121,7 @@ OUString getCasePreservingUrl(INetURLObject url) { DateTime convert(css::util::DateTime const & dt) { return DateTime( Date(dt.Day, dt.Month, dt.Year), - Time(dt.Hours, dt.Minutes, dt.Seconds, dt.HundredthSeconds)); + Time(dt.Hours, dt.Minutes, dt.Seconds, dt.NanoSeconds)); } } diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx index 97ec32d6bb44..aeeef95c77f9 100644 --- a/vcl/source/control/field2.cxx +++ b/vcl/source/control/field2.cxx @@ -2452,9 +2452,11 @@ sal_Bool TimeFormatter::ImplTimeReformat( const OUString& rStr, OUString& rOutSt n += aTempTime.GetSec(); rOutStr = OUString::number( n ); rOutStr += ImplGetLocaleDataWrapper().getTime100SecSep(); - if ( aTempTime.Get100Sec() < 10 ) - rOutStr += "0"; - rOutStr += OUString::number( aTempTime.Get100Sec() ); + std::ostringstream ostr; + ostr.fill('0'); + ostr.width(9); + ostr << aTempTime.GetNanoSec(); + rOutStr += OUString::createFromAscii(ostr.str().c_str()); } else if ( mbDuration ) rOutStr = ImplGetLocaleDataWrapper().getDuration( aTempTime, bSecond, b100Sec ); @@ -2755,9 +2757,11 @@ void TimeFormatter::ImplSetUserTime( const Time& rNewTime, Selection* pNewSelect n += aNewTime.GetSec(); aStr = OUString::number( n ); aStr += ImplGetLocaleDataWrapper().getTime100SecSep(); - if ( aNewTime.Get100Sec() < 10 ) - aStr += "0"; - aStr += OUString::number( aNewTime.Get100Sec() ); + std::ostringstream ostr; + ostr.fill('0'); + ostr.width(9); + ostr << aNewTime.GetNanoSec(); + aStr += OUString::createFromAscii(ostr.str().c_str()); } else if ( mbDuration ) { diff --git a/wizards/com/sun/star/wizards/common/JavaTools.java b/wizards/com/sun/star/wizards/common/JavaTools.java index 4d003b0c2470..37004bd4efff 100644 --- a/wizards/com/sun/star/wizards/common/JavaTools.java +++ b/wizards/com/sun/star/wizards/common/JavaTools.java @@ -433,7 +433,7 @@ public class JavaTools dt.Hours = (short) cal.get(Calendar.HOUR); dt.Minutes = (short) cal.get(Calendar.MINUTE); dt.Seconds = (short) cal.get(Calendar.SECOND); - dt.HundredthSeconds = (short) cal.get(Calendar.MILLISECOND); + dt.NanoSeconds = cal.get(Calendar.MILLISECOND)*1000000; return dt; } diff --git a/xmloff/source/core/xmluconv.cxx b/xmloff/source/core/xmluconv.cxx index 23b850052419..6c247711cbc0 100644 --- a/xmloff/source/core/xmluconv.cxx +++ b/xmloff/source/core/xmluconv.cxx @@ -30,6 +30,7 @@ #include <rtl/logfile.hxx> #include <tools/date.hxx> +#include <tools/time.hxx> #include <tools/fldunit.hxx> #include <com/sun/star/util/XNumberFormatsSupplier.hpp> @@ -438,11 +439,11 @@ sal_Bool SvXMLUnitConverter::convertDateTime( double& fDateTime, double Hour = aDateTime.Hours; double Min = aDateTime.Minutes; double Sec = aDateTime.Seconds; - double Sec100 = aDateTime.HundredthSeconds; - fTempDateTime += Hour / 24; - fTempDateTime += Min / (24 * 60); - fTempDateTime += Sec / (24 * 60 * 60); - fTempDateTime += Sec100 / (24 * 60 * 60 * 100); + double NanoSec = aDateTime.NanoSeconds; + fTempDateTime += Hour / ::Time::hourPerDay; + fTempDateTime += Min / ::Time::minutePerDay; + fTempDateTime += Sec / ::Time::secondPerDay; + fTempDateTime += NanoSec / ::Time::nanoSecPerDay; fDateTime = fTempDateTime; } return bSuccess; diff --git a/xmloff/source/draw/animationimport.cxx b/xmloff/source/draw/animationimport.cxx index 67e4f44a1cc6..035fe7eb6366 100644 --- a/xmloff/source/draw/animationimport.cxx +++ b/xmloff/source/draw/animationimport.cxx @@ -1161,7 +1161,7 @@ void AnimationNodeContext::init_node( const ::com::sun::star::uno::Reference< : { fInterval = ((((aDuration.Hours * 60) + aDuration.Minutes) * 60) + aDuration.Seconds) - + (aDuration.MilliSeconds / 1000.0); + + (aDuration.NanoSeconds / 1000000000.0); } } else diff --git a/xmloff/source/draw/propimp0.cxx b/xmloff/source/draw/propimp0.cxx index 51394da2e074..82c1dda41c12 100644 --- a/xmloff/source/draw/propimp0.cxx +++ b/xmloff/source/draw/propimp0.cxx @@ -28,6 +28,7 @@ #include <xmloff/xmluconv.hxx> #include <xmloff/xmlimp.hxx> +#include <tools/time.hxx> using namespace ::com::sun::star; @@ -55,7 +56,7 @@ sal_Bool XMLDurationPropertyHdl::importXML( ::sax::Converter::convertDuration(aDuration, rStrImpValue); const double fSeconds = ((aDuration.Days * 24 + aDuration.Hours) * 60 - + aDuration.Minutes) * 60 + aDuration.Seconds + aDuration.MilliSeconds / 1000.0; + + aDuration.Minutes) * 60 + aDuration.Seconds + aDuration.NanoSeconds / static_cast<double>(::Time::nanoSecPerSec); rValue <<= fSeconds; return sal_True; @@ -72,7 +73,7 @@ sal_Bool XMLDurationPropertyHdl::exportXML( { util::Duration aDuration; aDuration.Seconds = static_cast<sal_uInt16>(nVal); - aDuration.MilliSeconds = static_cast<sal_uInt32>(nVal * 1000.0) % 1000 ; + aDuration.NanoSeconds = static_cast<sal_uInt32>((nVal - aDuration.Seconds) * ::Time::nanoSecPerSec); OUStringBuffer aOut; ::sax::Converter::convertDuration(aOut, aDuration); diff --git a/xmloff/source/forms/elementexport.cxx b/xmloff/source/forms/elementexport.cxx index bc53c1e213bb..b10fa4370ce3 100644 --- a/xmloff/source/forms/elementexport.cxx +++ b/xmloff/source/forms/elementexport.cxx @@ -1150,7 +1150,7 @@ namespace xmloff aDuration.Hours = aTime.GetHour(); aDuration.Minutes = aTime.GetMin(); aDuration.Seconds = aTime.GetSec(); - aDuration.MilliSeconds = nRepeatDelay % 1000; + aDuration.NanoSeconds = (nRepeatDelay % 1000) * 1000000; OUStringBuffer buf; ::sax::Converter::convertDuration(buf, aDuration); diff --git a/xmloff/source/forms/elementimport.cxx b/xmloff/source/forms/elementimport.cxx index 9e2bb7ef6742..9d180b04e65a 100644 --- a/xmloff/source/forms/elementimport.cxx +++ b/xmloff/source/forms/elementimport.cxx @@ -822,7 +822,7 @@ namespace xmloff aProp.Name = PROPERTY_REPEAT_DELAY; sal_Int32 const nMS = ((aDuration.Hours * 60 + aDuration.Minutes) * 60 - + aDuration.Seconds) * 1000 + aDuration.MilliSeconds; + + aDuration.Seconds) * 1000 + aDuration.NanoSeconds/1000000; aProp.Value <<= nMS; implPushBackPropertyValue(aProp); diff --git a/xmloff/source/forms/handler/vcl_time_handler.cxx b/xmloff/source/forms/handler/vcl_time_handler.cxx index 4339ed75c791..c73392f75a14 100644 --- a/xmloff/source/forms/handler/vcl_time_handler.cxx +++ b/xmloff/source/forms/handler/vcl_time_handler.cxx @@ -64,7 +64,7 @@ namespace xmloff aDuration.Hours = aVCLTime.GetHour(); aDuration.Minutes = aVCLTime.GetMin(); aDuration.Seconds = aVCLTime.GetSec(); - aDuration.MilliSeconds = aVCLTime.Get100Sec() * 10; + aDuration.NanoSeconds = aVCLTime.GetNanoSec(); OUStringBuffer aBuffer; ::sax::Converter::convertDuration( aBuffer, aDuration ); @@ -80,7 +80,7 @@ namespace xmloff if (::sax::Converter::convertDuration( aDuration, i_attributeValue )) { ::Time aVCLTime(aDuration.Hours, aDuration.Minutes, - aDuration.Seconds, aDuration.MilliSeconds / 10); + aDuration.Seconds, aDuration.NanoSeconds); nVCLTime = aVCLTime.GetTime(); } else diff --git a/xmloff/source/forms/propertyexport.cxx b/xmloff/source/forms/propertyexport.cxx index a0de21a02029..73f5e1dddc2e 100644 --- a/xmloff/source/forms/propertyexport.cxx +++ b/xmloff/source/forms/propertyexport.cxx @@ -590,16 +590,20 @@ namespace xmloff } else if (_rValue >>= aTime) { - fValue = ((aTime.Hours * 60 + aTime.Minutes) * 60 + aTime.Seconds) * 100 + aTime.HundredthSeconds; - fValue = fValue / 8640000.0; + fValue = aTime.Hours / static_cast<double>(::Time::hourPerDay) + + aTime.Minutes / static_cast<double>(::Time::minutePerDay) + + aTime.Seconds / static_cast<double>(::Time::secondPerDay) + + aTime.NanoSeconds / static_cast<double>(::Time::nanoSecPerDay); } else if (_rValue >>= aDateTime) { DateTime aToolsDateTime( DateTime::EMPTY ); ::utl::typeConvert(aDateTime, aToolsDateTime); // the time part (the digits behind the comma) - fValue = ((aDateTime.Hours * 60 + aDateTime.Minutes) * 60 + aDateTime.Seconds) * 100 + aDateTime.HundredthSeconds; - fValue = fValue / 8640000.0; + fValue = aTime.Hours / static_cast<double>(::Time::hourPerDay) + + aTime.Minutes / static_cast<double>(::Time::minutePerDay) + + aTime.Seconds / static_cast<double>(::Time::secondPerDay) + + aTime.NanoSeconds / static_cast<double>(::Time::nanoSecPerDay); // plus the data part (the digits in front of the comma) fValue += aToolsDateTime.GetDate(); } diff --git a/xmloff/source/forms/propertyimport.cxx b/xmloff/source/forms/propertyimport.cxx index a6c667c27166..53f249a13dd3 100644 --- a/xmloff/source/forms/propertyimport.cxx +++ b/xmloff/source/forms/propertyimport.cxx @@ -30,6 +30,7 @@ #include "callbacks.hxx" #include "xmloff/xmlnmspe.hxx" #include <tools/date.hxx> +#include <tools/time.hxx> #include <com/sun/star/util/Date.hpp> #include <com/sun/star/util/Time.hpp> #include <com/sun/star/util/DateTime.hpp> @@ -67,16 +68,15 @@ namespace ::com::sun::star::util::Time lcl_getTime(double _nValue) { ::com::sun::star::util::Time aTime; - sal_uInt32 nIntValue = sal_Int32(_nValue * 8640000); - nIntValue *= 8640000; - aTime.HundredthSeconds = (sal_uInt16)( nIntValue % 100 ); - nIntValue /= 100; - aTime.Seconds = (sal_uInt16)( nIntValue % 60 ); - nIntValue /= 60; - aTime.Minutes = (sal_uInt16)( nIntValue % 60 ); - nIntValue /= 60; + sal_uInt64 nIntValue = static_cast<sal_uInt64>(_nValue * ::Time::nanoSecPerDay); + aTime.NanoSeconds = nIntValue % ::Time::nanoSecPerSec; + nIntValue /= ::Time::nanoSecPerSec; + aTime.Seconds = nIntValue % ::Time::secondPerMinute; + nIntValue /= ::Time::secondPerMinute; + aTime.Minutes = nIntValue % ::Time::minutePerHour; + nIntValue /= ::Time::minutePerHour; OSL_ENSURE(nIntValue < 24, "lcl_getTime: more than a day?"); - aTime.Hours = static_cast< sal_uInt16 >( nIntValue ); + aTime.Hours = nIntValue; return aTime; } @@ -219,7 +219,7 @@ Any PropertyConversion::convertString( SvXMLImport& _rImporter, const ::com::sun ::com::sun::star::util::Date aDate = lcl_getDate(nValue); ::com::sun::star::util::DateTime aDateTime; - aDateTime.HundredthSeconds = aTime.HundredthSeconds; + aDateTime.NanoSeconds = aTime.NanoSeconds; aDateTime.Seconds = aTime.Seconds; aDateTime.Minutes = aTime.Minutes; aDateTime.Hours = aTime.Hours; diff --git a/xmloff/source/style/durationhdl.cxx b/xmloff/source/style/durationhdl.cxx index 73cae30f78be..676f26050510 100644 --- a/xmloff/source/style/durationhdl.cxx +++ b/xmloff/source/style/durationhdl.cxx @@ -39,8 +39,11 @@ sal_Bool XMLDurationMS16PropHdl_Impl::importXML( if (!::sax::Converter::convertDuration( aDuration, rStrImpValue )) return false; + // TODO FIXME why is this in centiseconds? Should it be nanoseconds? + // This overflows... 24h == 8640000cs >> 0x7FFF cs == 32767 + // 32767cs = approx 5 minutes and 27.67s const sal_Int16 nMS = ((aDuration.Hours * 60 + aDuration.Minutes) * 60 - + aDuration.Seconds) * 100 + (aDuration.MilliSeconds / 10); + + aDuration.Seconds) * 100 + (aDuration.NanoSeconds / (10*1000*1000)); rValue <<= nMS; return sal_True; diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx index e53736572f27..7e013db446e4 100644 --- a/xmloff/source/text/txtflde.cxx +++ b/xmloff/source/text/txtflde.cxx @@ -2645,7 +2645,7 @@ void XMLTextFieldExport::ProcessDateTime(enum XMLTokenEnum eName, // truncate dates if(bIsDate) { - aDateTime.HundredthSeconds = 0; + aDateTime.NanoSeconds = 0; aDateTime.Seconds = 0; aDateTime.Minutes = 0; aDateTime.Hours = 0; diff --git a/xmloff/source/xforms/SchemaRestrictionContext.cxx b/xmloff/source/xforms/SchemaRestrictionContext.cxx index facfafbcdc07..34b64ae12fcb 100644 --- a/xmloff/source/xforms/SchemaRestrictionContext.cxx +++ b/xmloff/source/xforms/SchemaRestrictionContext.cxx @@ -215,7 +215,7 @@ Any xforms_time( const OUString& rValue ) aTime.Hours = aDuration.Hours; aTime.Minutes = aDuration.Minutes; aTime.Seconds = aDuration.Seconds; - aTime.HundredthSeconds = aDuration.MilliSeconds / 10; + aTime.NanoSeconds = aDuration.NanoSeconds; aAny <<= aTime; } return aAny; diff --git a/xmloff/source/xforms/xformsexport.cxx b/xmloff/source/xforms/xformsexport.cxx index a19d11acf6f9..28ba107ab108 100644 --- a/xmloff/source/xforms/xformsexport.cxx +++ b/xmloff/source/xforms/xformsexport.cxx @@ -688,7 +688,7 @@ void xforms_formatTime( OUStringBuffer& aBuffer, const com::sun::star::util::Tim aDuration.Hours = rTime.Hours; aDuration.Minutes = rTime.Minutes; aDuration.Seconds = rTime.Seconds; - aDuration.MilliSeconds = rTime.HundredthSeconds * 10; + aDuration.NanoSeconds = rTime.NanoSeconds; ::sax::Converter::convertDuration( aBuffer, aDuration ); } diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index 4d366f42518b..5993122837cb 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -309,7 +309,7 @@ DocumentDigitalSignatures::ImplVerifySignatures( // Time support again (#i38744#) Date aDate( rInfo.stDateTime.Day, rInfo.stDateTime.Month, rInfo.stDateTime.Year ); Time aTime( rInfo.stDateTime.Hours, rInfo.stDateTime.Minutes, - rInfo.stDateTime.Seconds, rInfo.stDateTime.HundredthSeconds ); + rInfo.stDateTime.Seconds, rInfo.stDateTime.NanoSeconds ); rSigInfo.SignatureDate = aDate.GetDate(); rSigInfo.SignatureTime = aTime.GetTime(); diff --git a/xmlsecurity/source/dialogs/resourcemanager.cxx b/xmlsecurity/source/dialogs/resourcemanager.cxx index defcae055dd0..2611960df028 100644 --- a/xmlsecurity/source/dialogs/resourcemanager.cxx +++ b/xmlsecurity/source/dialogs/resourcemanager.cxx @@ -54,7 +54,7 @@ namespace XmlSec { return DateTime( Date( _rDT.Day, _rDT.Month, _rDT.Year ), - Time( _rDT.Hours, _rDT.Minutes, _rDT.Seconds, _rDT.HundredthSeconds ) ); + Time( _rDT.Hours, _rDT.Minutes, _rDT.Seconds, _rDT.NanoSeconds ) ); } OUString GetDateTimeString( const ::com::sun::star::util::DateTime& _rDT ) diff --git a/xmlsecurity/source/helper/xmlsignaturehelper.cxx b/xmlsecurity/source/helper/xmlsignaturehelper.cxx index 6aeb9965ec79..b5e2869b4031 100644 --- a/xmlsecurity/source/helper/xmlsignaturehelper.cxx +++ b/xmlsecurity/source/helper/xmlsignaturehelper.cxx @@ -124,7 +124,7 @@ void XMLSignatureHelper::SetX509Certificate( void XMLSignatureHelper::SetDateTime( sal_Int32 nSecurityId, const Date& rDate, const Time& rTime ) { ::com::sun::star::util::DateTime stDateTime; - stDateTime.HundredthSeconds = (::sal_uInt16)rTime.Get100Sec(); + stDateTime.NanoSeconds = rTime.GetNanoSec(); stDateTime.Seconds = (::sal_uInt16)rTime.GetSec(); stDateTime.Minutes = (::sal_uInt16)rTime.GetMin(); stDateTime.Hours = (::sal_uInt16)rTime.GetHour(); diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx index 733022c43678..addfc3ea3d2b 100644 --- a/xmlsecurity/source/helper/xsecctl.cxx +++ b/xmlsecurity/source/helper/xsecctl.cxx @@ -30,6 +30,7 @@ #include <xmloff/attrlist.hxx> #include <rtl/math.hxx> +#include <unotools/datetime.hxx> namespace cssu = com::sun::star::uno; namespace cssl = com::sun::star::lang; @@ -66,199 +67,6 @@ XSecController::~XSecController() /* * private methods */ -/** convert string to number with optional min and max values */ -sal_Bool XSecController::convertNumber( sal_Int32& rValue, - const OUString& rString, - sal_Int32 /*nMin*/, sal_Int32 /*nMax*/ ) -{ - sal_Bool bNeg = sal_False; - rValue = 0; - - sal_Int32 nPos = 0L; - sal_Int32 nLen = rString.getLength(); - - // skip white space - while( nPos < nLen && sal_Unicode(' ') == rString[nPos] ) - nPos++; - - if( nPos < nLen && sal_Unicode('-') == rString[nPos] ) - { - bNeg = sal_True; - nPos++; - } - - // get number - while( nPos < nLen && - sal_Unicode('0') <= rString[nPos] && - sal_Unicode('9') >= rString[nPos] ) - { - // TODO: check overflow! - rValue *= 10; - rValue += (rString[nPos] - sal_Unicode('0')); - nPos++; - } - - if( bNeg ) - rValue *= -1; - - return nPos == nLen; -} - -/** convert util::DateTime to ISO Date String */ -void XSecController::convertDateTime( OUStringBuffer& rBuffer, - const com::sun::star::util::DateTime& rDateTime ) -{ - rBuffer.append((sal_Int32) rDateTime.Year); - rBuffer.append('-'); - if( rDateTime.Month < 10 ) - rBuffer.append('0'); - rBuffer.append((sal_Int32) rDateTime.Month); - rBuffer.append('-'); - if( rDateTime.Day < 10 ) - rBuffer.append('0'); - rBuffer.append((sal_Int32) rDateTime.Day); - - if( rDateTime.Seconds != 0 || - rDateTime.Minutes != 0 || - rDateTime.Hours != 0 ) - { - rBuffer.append('T'); - if( rDateTime.Hours < 10 ) - rBuffer.append('0'); - rBuffer.append((sal_Int32) rDateTime.Hours); - rBuffer.append(':'); - if( rDateTime.Minutes < 10 ) - rBuffer.append('0'); - rBuffer.append((sal_Int32) rDateTime.Minutes); - rBuffer.append(':'); - if( rDateTime.Seconds < 10 ) - rBuffer.append('0'); - rBuffer.append((sal_Int32) rDateTime.Seconds); - if ( rDateTime.HundredthSeconds > 0) - { - rBuffer.append(','); - if (rDateTime.HundredthSeconds < 10) - rBuffer.append('0'); - rBuffer.append((sal_Int32) rDateTime.HundredthSeconds); - } - } -} - -/** convert ISO Date String to util::DateTime */ -sal_Bool XSecController::convertDateTime( com::sun::star::util::DateTime& rDateTime, - const OUString& rString ) -{ - sal_Bool bSuccess = sal_True; - - OUString aDateStr, aTimeStr, sHundredth; - sal_Int32 nPos = rString.indexOf( (sal_Unicode) 'T' ); - sal_Int32 nPos2 = rString.indexOf( (sal_Unicode) ',' ); - if ( nPos >= 0 ) - { - aDateStr = rString.copy( 0, nPos ); - if ( nPos2 >= 0 ) - { - aTimeStr = rString.copy( nPos + 1, nPos2 - nPos - 1 ); - - //Get the fraction of a second with the accuracy of one hundreds second. - //The fraction part of the date could have different accuracies. To calculate - //the count of a hundredth units one could form a fractional number by appending - //the value of the time string to 0. Then multiply it by 100 and use only the whole number. - //For example: 5:27:46,1 -> 0,1 * 100 = 10 - //5:27:46,01 -> 0,01 * 100 = 1 - //5:27:46,001 -> 0,001 * 100 = 0 - //Due to the inaccuracy of floating point numbers the result may not be the same on different - //platforms. We had the case where we had a value of 24 hundredth of second, which converted to - //23 on Linux and 24 on Solaris and Windows. - - //we only support a hundredth second - //make ,1 -> 10 ,01 -> 1 ,001 -> only use first two diggits - sHundredth = rString.copy(nPos2 + 1); - sal_Int32 len = sHundredth.getLength(); - if (len == 1) - sHundredth += OUString("0"); - if (len > 2) - sHundredth = sHundredth.copy(0, 2); - } - else - { - aTimeStr = rString.copy(nPos + 1); - sHundredth = OUString("0"); - } - } - else - aDateStr = rString; // no separator: only date part - - sal_Int32 nYear = 1899; - sal_Int32 nMonth = 12; - sal_Int32 nDay = 30; - sal_Int32 nHour = 0; - sal_Int32 nMin = 0; - sal_Int32 nSec = 0; - - const sal_Unicode* pStr = aDateStr.getStr(); - sal_Int32 nDateTokens = 1; - while ( *pStr ) - { - if ( *pStr == '-' ) - nDateTokens++; - pStr++; - } - if ( nDateTokens > 3 || aDateStr.isEmpty() ) - bSuccess = sal_False; - else - { - sal_Int32 n = 0; - if ( !convertNumber( nYear, aDateStr.getToken( 0, '-', n ), 0, 9999 ) ) - bSuccess = sal_False; - if ( nDateTokens >= 2 ) - if ( !convertNumber( nMonth, aDateStr.getToken( 0, '-', n ), 0, 12 ) ) - bSuccess = sal_False; - if ( nDateTokens >= 3 ) - if ( !convertNumber( nDay, aDateStr.getToken( 0, '-', n ), 0, 31 ) ) - bSuccess = sal_False; - } - - if ( !aTimeStr.isEmpty() ) // time is optional - { - pStr = aTimeStr.getStr(); - sal_Int32 nTimeTokens = 1; - while ( *pStr ) - { - if ( *pStr == ':' ) - nTimeTokens++; - pStr++; - } - if ( nTimeTokens > 3 ) - bSuccess = sal_False; - else - { - sal_Int32 n = 0; - if ( !convertNumber( nHour, aTimeStr.getToken( 0, ':', n ), 0, 23 ) ) - bSuccess = sal_False; - if ( nTimeTokens >= 2 ) - if ( !convertNumber( nMin, aTimeStr.getToken( 0, ':', n ), 0, 59 ) ) - bSuccess = sal_False; - if ( nTimeTokens >= 3 ) - if ( !convertNumber( nSec, aTimeStr.getToken( 0, ':', n ), 0, 59 ) ) - bSuccess = sal_False; - } - } - - if (bSuccess) - { - rDateTime.Year = (sal_uInt16)nYear; - rDateTime.Month = (sal_uInt16)nMonth; - rDateTime.Day = (sal_uInt16)nDay; - rDateTime.Hours = (sal_uInt16)nHour; - rDateTime.Minutes = (sal_uInt16)nMin; - rDateTime.Seconds = (sal_uInt16)nSec; - // rDateTime.HundredthSeconds = sDoubleStr.toDouble() * 100; - rDateTime.HundredthSeconds = static_cast<sal_uInt16>(sHundredth.toInt32()); - } - return bSuccess; -} - int XSecController::findSignatureInfor( sal_Int32 nSecurityId) const /****** XSecController/findSignatureInfor ************************************* * @@ -1123,16 +931,14 @@ void XSecController::exportSignature( OUStringBuffer buffer; //If the xml signature was already contained in the document, //then we use the original date and time string, rather then the - //converted one. When the original string is converted to the DateTime - //structure then information may be lost because it only holds a fractional - //of a second with a accuracy of one hundredth of second. If the string contains - //milli seconds (document was signed by an application other than OOo) - //and the converted time is written back, then the string looks different - //and the signature is broken. + //converted one. This avoids writing a different string due to + //e.g. rounding issues and thus breaking the signature. if (!signatureInfo.ouDateTime.isEmpty()) buffer = signatureInfo.ouDateTime; else - convertDateTime( buffer, signatureInfo.stDateTime ); + { + buffer = utl::toISO8601(signatureInfo.stDateTime); + } xDocumentHandler->characters( buffer.makeStringAndClear() ); xDocumentHandler->endElement( diff --git a/xmlsecurity/source/helper/xsecctl.hxx b/xmlsecurity/source/helper/xsecctl.hxx index 6014807de6bc..40f47aceeda7 100644 --- a/xmlsecurity/source/helper/xsecctl.hxx +++ b/xmlsecurity/source/helper/xsecctl.hxx @@ -345,10 +345,6 @@ private: /* * Common methods */ - sal_Bool convertNumber( sal_Int32& rValue, const OUString& rString, sal_Int32 nMin, sal_Int32 nMax ); - void convertDateTime( OUStringBuffer& rBuffer, const com::sun::star::util::DateTime& rDateTime ); - sal_Bool convertDateTime( com::sun::star::util::DateTime& rDateTime, const OUString& rString ); - void createXSecComponent( ); int findSignatureInfor( sal_Int32 nSecurityId ) const; bool chainOn( bool bRetrievingLastEvent ); diff --git a/xmlsecurity/source/helper/xsecverify.cxx b/xmlsecurity/source/helper/xsecverify.cxx index 3b559ebe0022..67d5b2fd6b42 100644 --- a/xmlsecurity/source/helper/xsecverify.cxx +++ b/xmlsecurity/source/helper/xsecverify.cxx @@ -29,6 +29,7 @@ #include <com/sun/star/xml/crypto/sax/XSignatureVerifyResultBroadcaster.hpp> #include <com/sun/star/xml/sax/SAXParseException.hpp> #include <sal/log.hxx> +#include <unotools/datetime.hxx> namespace cssu = com::sun::star::uno; namespace cssl = com::sun::star::lang; @@ -258,7 +259,7 @@ void XSecController::setDate( OUString& ouDate ) return; } InternalSignatureInformation &isi = m_vInternalSignatureInformations.back(); - convertDateTime( isi.signatureInfor.stDateTime, ouDate ); + utl::ISO8601parseDateTime( ouDate, isi.signatureInfor.stDateTime); isi.signatureInfor.ouDateTime = ouDate; } diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx index 2ec2145a7ca6..34e7e452b7ff 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx +++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx @@ -31,6 +31,7 @@ #include <osl/nlsupport.h> #include <osl/process.h> #include <utility> +#include <tools/time.hxx> using namespace ::com::sun::star::uno ; using namespace ::com::sun::star::security ; @@ -301,7 +302,7 @@ OUString SAL_CALL X509Certificate_MSCryptImpl :: getSubjectName() throw ( ::com: { if( FileTimeToSystemTime( &localFileTime, &explTime ) ) { //Convert the time to readable local time - dateTime.HundredthSeconds = explTime.wMilliseconds / 100 ; + dateTime.NanoSeconds = explTime.wMilliseconds * ::Time::nanoPerMilli ; dateTime.Seconds = explTime.wSecond ; dateTime.Minutes = explTime.wMinute ; dateTime.Hours = explTime.wHour ; @@ -327,7 +328,7 @@ OUString SAL_CALL X509Certificate_MSCryptImpl :: getSubjectName() throw ( ::com: { if( FileTimeToSystemTime( &localFileTime, &explTime ) ) { //Convert the time to readable local time - dateTime.HundredthSeconds = explTime.wMilliseconds / 100 ; + dateTime.NanoSeconds = explTime.wMilliseconds * ::Time::nanoPerMilli ; dateTime.Seconds = explTime.wSecond ; dateTime.Minutes = explTime.wMinute ; dateTime.Hours = explTime.wHour ; diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx index 3e81cd6b102f..72d4831cbf6a 100644 --- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx @@ -33,6 +33,7 @@ #include "certificateextension_xmlsecimpl.hxx" #include "sanextension_nssimpl.hxx" +#include <tools/time.hxx> using namespace ::com::sun::star::uno ; using namespace ::com::sun::star::security ; @@ -106,7 +107,7 @@ OUString SAL_CALL X509Certificate_NssImpl :: getSubjectName() throw ( ::com::sun //Convert the time to readable local time PR_ExplodeTime( notBefore, PR_LocalTimeParameters, &explTime ) ; - dateTime.HundredthSeconds = static_cast< sal_Int16 >( explTime.tm_usec / 1000 ); + dateTime.NanoSeconds = static_cast< sal_Int32 >( explTime.tm_usec * ::Time::nanoPerMicro ); dateTime.Seconds = static_cast< sal_Int16 >( explTime.tm_sec ); dateTime.Minutes = static_cast< sal_Int16 >( explTime.tm_min ); dateTime.Hours = static_cast< sal_Int16 >( explTime.tm_hour ); @@ -135,7 +136,7 @@ OUString SAL_CALL X509Certificate_NssImpl :: getSubjectName() throw ( ::com::sun //Convert the time to readable local time PR_ExplodeTime( notAfter, PR_LocalTimeParameters, &explTime ) ; - dateTime.HundredthSeconds = static_cast< sal_Int16 >( explTime.tm_usec / 1000 ); + dateTime.NanoSeconds = static_cast< sal_Int16 >( explTime.tm_usec * ::Time::nanoPerMicro ); dateTime.Seconds = static_cast< sal_Int16 >( explTime.tm_sec ); dateTime.Minutes = static_cast< sal_Int16 >( explTime.tm_min ); dateTime.Hours = static_cast< sal_Int16 >( explTime.tm_hour ); |