diff options
author | Lionel Elie Mamane <lionel@mamane.lu> | 2013-03-17 08:36:26 +0100 |
---|---|---|
committer | Lionel Elie Mamane <lionel@mamane.lu> | 2013-04-18 21:34:46 +0200 |
commit | 9830fd36dbdb72c79703b0c61efc027fba793c5a (patch) | |
tree | 2e9d698e6ca109dc6627adb5c84aa2b635bcfe92 /xmloff | |
parent | 5aaaf0694b6e3213685563fc3bc90d19b10f5c75 (diff) |
date/time IDL datatypes incompatible change
- nanosecond precision
- signed (allowed negative) year
Also: assorted improvements / bugfixes in date/time handling code.
Some factorisation of copy/pasted code.
Change-Id: I761a1b0b8731c82f19a0c37acbcf43d3c06d6cd6
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/xmluconv.cxx | 11 | ||||
-rw-r--r-- | xmloff/source/draw/animationimport.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/draw/propimp0.cxx | 5 | ||||
-rw-r--r-- | xmloff/source/forms/elementexport.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/forms/elementimport.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/forms/handler/vcl_time_handler.cxx | 4 | ||||
-rw-r--r-- | xmloff/source/forms/propertyexport.cxx | 12 | ||||
-rw-r--r-- | xmloff/source/forms/propertyimport.cxx | 20 | ||||
-rw-r--r-- | xmloff/source/style/durationhdl.cxx | 5 | ||||
-rw-r--r-- | xmloff/source/text/txtflde.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/xforms/SchemaRestrictionContext.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/xforms/xformsexport.cxx | 2 |
12 files changed, 39 insertions, 30 deletions
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 ); } |