writerfilter/source/dmapper/ConversionHelper.cxx | 26 +++++++++++++++++- writerfilter/source/dmapper/ConversionHelper.hxx | 1 writerfilter/source/dmapper/DomainMapper_Impl.cxx | 31 +--------------------- 3 files changed, 28 insertions(+), 30 deletions(-)
New commits: commit 94429caa64a1dca701f0b120f669bdd561b6ced9 Author: Adam Co <rattles2...@gmail.com> Date: Mon Feb 3 16:53:17 2014 +0200 Refactor the code for converting 'Date' string to 'DateTime' Change-Id: I20632258709856cd4c6680e1c8a1d92271ad0453 Reviewed-on: https://gerrit.libreoffice.org/7817 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Miklos Vajna <vmik...@collabora.co.uk> diff --git a/writerfilter/source/dmapper/ConversionHelper.cxx b/writerfilter/source/dmapper/ConversionHelper.cxx index 102e5c8..c39859d 100644 --- a/writerfilter/source/dmapper/ConversionHelper.cxx +++ b/writerfilter/source/dmapper/ConversionHelper.cxx @@ -254,7 +254,6 @@ sal_Int32 ConvertColor(sal_Int32 nWordColor) return nRet; } - sal_Int16 convertTableJustification( sal_Int32 nIntValue ) { sal_Int16 nOrient = text::HoriOrientation::LEFT_AND_WIDTH; @@ -412,6 +411,31 @@ sal_Int16 ConvertNumberingType(sal_Int32 nFmt) return nRet; } +com::sun::star::util::DateTime ConvertDateStringToDateTime( const OUString& rDateTime ) +{ + com::sun::star::util::DateTime aDateTime; + //xsd::DateTime in the format [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] example: 2008-01-21T10:42:00Z + //OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(()) + sal_Int32 nIndex = 0; + OUString sDate = rDateTime.getToken( 0, 'T', nIndex ); + // HACK: this is broken according to the spec, but MSOffice always treats the time as local, + // and writes it as Z (=UTC+0) + OUString sTime = rDateTime.getToken( 0, 'Z', nIndex ); + nIndex = 0; + aDateTime.Year = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() ); + aDateTime.Month = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() ); + if (nIndex != -1) + aDateTime.Day = sal_uInt16( sDate.copy( nIndex ).toInt32() ); + + nIndex = 0; + aDateTime.Hours = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() ); + aDateTime.Minutes = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() ); + if (nIndex != -1) + aDateTime.Seconds = sal_uInt16( sTime.copy( nIndex ).toInt32() ); + + return aDateTime; +} + } // namespace ConversionHelper } //namespace dmapper diff --git a/writerfilter/source/dmapper/ConversionHelper.hxx b/writerfilter/source/dmapper/ConversionHelper.hxx index 352d29f..ff2fa7f 100644 --- a/writerfilter/source/dmapper/ConversionHelper.hxx +++ b/writerfilter/source/dmapper/ConversionHelper.hxx @@ -50,6 +50,7 @@ namespace ConversionHelper{ sal_Int16 convertTableJustification( sal_Int32 nIntValue ); sal_Int16 ConvertNumberingType(sal_Int32 nFmt); + com::sun::star::util::DateTime ConvertDateStringToDateTime( const OUString& rDateTime ); } // namespace ConversionHelper } //namespace dmapper } // namespace writerfilter diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 12855fe..26a7384 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1104,32 +1104,6 @@ void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap ) #endif } - -util::DateTime lcl_DateStringToDateTime( const OUString& rDateTime ) -{ - util::DateTime aDateTime; - //xsd::DateTime in the format [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] example: 2008-01-21T10:42:00Z - //OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(()) - sal_Int32 nIndex = 0; - OUString sDate = rDateTime.getToken( 0, 'T', nIndex ); - // HACK: this is broken according to the spec, but MSOffice always treats the time as local, - // and writes it as Z (=UTC+0) - OUString sTime = rDateTime.getToken( 0, 'Z', nIndex ); - nIndex = 0; - aDateTime.Year = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() ); - aDateTime.Month = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() ); - if (nIndex != -1) - aDateTime.Day = sal_uInt16( sDate.copy( nIndex ).toInt32() ); - - nIndex = 0; - aDateTime.Hours = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() ); - aDateTime.Minutes = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() ); - if (nIndex != -1) - aDateTime.Seconds = sal_uInt16( sTime.copy( nIndex ).toInt32() ); - - return aDateTime; -} - void DomainMapper_Impl::appendTextPortion( const OUString& rString, PropertyMapPtr pPropertyMap ) { if (m_bDiscardHeaderFooter) @@ -1549,10 +1523,9 @@ void DomainMapper_Impl::CreateRedline( uno::Reference< text::XTextRange > xRange pRedlineProperties[0].Name = rPropNameSupplier.GetName( PROP_REDLINE_AUTHOR ); pRedlineProperties[0].Value <<= pRedline->m_sAuthor; pRedlineProperties[1].Name = rPropNameSupplier.GetName( PROP_REDLINE_DATE_TIME ); - pRedlineProperties[1].Value <<= lcl_DateStringToDateTime( pRedline->m_sDate ); + pRedlineProperties[1].Value <<= ConversionHelper::ConvertDateStringToDateTime( pRedline->m_sDate ); pRedlineProperties[2].Name = rPropNameSupplier.GetName( PROP_REDLINE_REVERT_PROPERTIES ); pRedlineProperties[2].Value <<= pRedline->m_aRevertProperties; - xRedline->makeRedline( sType, aRedlineProperties ); } catch( const uno::Exception & ) @@ -3959,7 +3932,7 @@ void DomainMapper_Impl::SetCurrentRedlineDate( OUString sDate ) pCurrent->m_sDate = sDate; } else - m_xAnnotationField->setPropertyValue("DateTimeValue", uno::makeAny(lcl_DateStringToDateTime(sDate))); + m_xAnnotationField->setPropertyValue("DateTimeValue", uno::makeAny(ConversionHelper::ConvertDateStringToDateTime(sDate))); } void DomainMapper_Impl::SetCurrentRedlineId( sal_Int32 sId ) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits