diff options
author | Adam Co <rattles2013@gmail.com> | 2013-11-26 13:56:46 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2014-11-14 13:26:40 +0100 |
commit | 4ca3a96ff8b5c05aa8a4e48000a1ee485a59707a (patch) | |
tree | edc0349877a19ce455dd19e55e26b0600fa0f0ec | |
parent | 0524dee2a9a1b4ff43a19654ab73ff764e7cadef (diff) |
Moved 'DateTimeToOString' from 'filter' package to 'tools' package
After the move now other classes can convert DateTime to OString also
Reviewed on:
https://gerrit.libreoffice.org/6816
Conflicts:
sw/source/filter/ww8/docxattributeoutput.cxx
Change-Id: I0ceb9a5cc26103a6cb36d7765a717770ec3fbe7d
-rw-r--r-- | filter/source/msfilter/util.cxx | 44 | ||||
-rw-r--r-- | include/filter/msfilter/util.hxx | 1 | ||||
-rw-r--r-- | include/tools/datetimeutils.hxx | 20 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 5 | ||||
-rw-r--r-- | tools/Library_tl.mk | 1 | ||||
-rw-r--r-- | tools/source/datetime/datetimeutils.cxx | 56 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 3 |
7 files changed, 82 insertions, 48 deletions
diff --git a/filter/source/msfilter/util.cxx b/filter/source/msfilter/util.cxx index a10e4381d510..78e0504cbc58 100644 --- a/filter/source/msfilter/util.cxx +++ b/filter/source/msfilter/util.cxx @@ -79,50 +79,6 @@ DateTime DTTM2DateTime( long lDTTM ) return aDateTime; } -/// Append the number as 2-digit when less than 10. -static void lcl_AppendTwoDigits( OStringBuffer &rBuffer, sal_Int32 nNum ) -{ - if ( nNum < 0 || nNum > 99 ) - { - rBuffer.append( "00" ); - return; - } - - if ( nNum < 10 ) - rBuffer.append( '0' ); - - rBuffer.append( nNum ); -} - -OString DateTimeToOString( const DateTime& rDateTime ) -{ - DateTime aInUTC( rDateTime ); -// HACK: this is correct according to the spec, but MSOffice believes everybody lives -// in UTC+0 when reading it back -// aInUTC.ConvertToUTC(); - - OStringBuffer aBuffer( 25 ); - aBuffer.append( sal_Int32( aInUTC.GetYear() ) ); - aBuffer.append( '-' ); - - lcl_AppendTwoDigits( aBuffer, aInUTC.GetMonth() ); - aBuffer.append( '-' ); - - lcl_AppendTwoDigits( aBuffer, aInUTC.GetDay() ); - aBuffer.append( 'T' ); - - lcl_AppendTwoDigits( aBuffer, aInUTC.GetHour() ); - aBuffer.append( ':' ); - - lcl_AppendTwoDigits( aBuffer, aInUTC.GetMin() ); - aBuffer.append( ':' ); - - lcl_AppendTwoDigits( aBuffer, aInUTC.GetSec() ); - aBuffer.append( 'Z' ); // we are in UTC - - return aBuffer.makeStringAndClear(); -} - sal_Unicode bestFitOpenSymbolToMSFont(sal_Unicode cChar, rtl_TextEncoding& rChrSet, OUString& rFontName, bool bDisableUnicodeSupport) { diff --git a/include/filter/msfilter/util.hxx b/include/filter/msfilter/util.hxx index 38cdf56e7df2..22a39499258c 100644 --- a/include/filter/msfilter/util.hxx +++ b/include/filter/msfilter/util.hxx @@ -40,7 +40,6 @@ MSFILTER_DLLPUBLIC DateTime DTTM2DateTime( long lDTTM ); I guess there must be an implementation of this somewhere in LO, but I failed to find it, unfortunately :-( */ -MSFILTER_DLLPUBLIC OString DateTimeToOString( const DateTime& rDateTime ); /// Given a cBullet in encoding r_ioChrSet and fontname r_ioFontName return a /// suitable new Bullet and change r_ioChrSet and r_ioFontName to form the diff --git a/include/tools/datetimeutils.hxx b/include/tools/datetimeutils.hxx new file mode 100644 index 000000000000..840403bf002d --- /dev/null +++ b/include/tools/datetimeutils.hxx @@ -0,0 +1,20 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_TOOLS_DATETIMEUTILS_HXX +#define INCLUDED_TOOLS_DATETIMEUTILS_HXX + +#include <tools/datetime.hxx> + +// This function converts a 'DateTime' object to an 'OString' object +TOOLS_DLLPUBLIC OString DateTimeToOString( const DateTime& rDateTime ); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 4b6eb3916b76..429901090c43 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -75,6 +75,7 @@ #include <svx/xfillit0.hxx> #include <svx/xflgrit.hxx> #include <sfx2/sfxbasemodel.hxx> +#include <tools/datetimeutils.hxx> #include <anchoredobject.hxx> #include <docufld.hxx> @@ -1392,7 +1393,7 @@ void DocxAttributeOutput::StartRedline() const String &rAuthor( SW_MOD()->GetRedlineAuthor( pRedlineData->GetAuthor() ) ); OString aAuthor( OUStringToOString( rAuthor, RTL_TEXTENCODING_UTF8 ) ); - OString aDate( msfilter::util::DateTimeToOString( pRedlineData->GetTimeStamp() ) ); + OString aDate( DateTimeToOString( pRedlineData->GetTimeStamp() ) ); switch ( pRedlineData->GetType() ) { @@ -4016,7 +4017,7 @@ void DocxAttributeOutput::WritePostitFields() const SwPostItField* f = m_postitFields[ i ]; m_pSerializer->startElementNS( XML_w, XML_comment, FSNS( XML_w, XML_id ), idstr.getStr(), FSNS( XML_w, XML_author ), OUStringToOString( f->GetPar1(), RTL_TEXTENCODING_UTF8 ).getStr(), - FSNS( XML_w, XML_date ), msfilter::util::DateTimeToOString(f->GetDateTime()).getStr(), + FSNS( XML_w, XML_date ), DateTimeToOString(f->GetDateTime()).getStr(), FSNS( XML_w, XML_initials ), OUStringToOString( f->GetInitials(), RTL_TEXTENCODING_UTF8 ).getStr(), FSEND ); // Check for the text object existing, it seems that it can be NULL when saving a newly created // comment without giving focus back to the main document. As GetTxt() is empty in that case as well, diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk index e0d19b84e358..c69f53b97da3 100644 --- a/tools/Library_tl.mk +++ b/tools/Library_tl.mk @@ -44,6 +44,7 @@ $(eval $(call gb_Library_use_libraries,tl,\ $(eval $(call gb_Library_add_exception_objects,tl,\ tools/source/datetime/datetime \ + tools/source/datetime/datetimeutils \ tools/source/datetime/tdate \ tools/source/datetime/ttime \ tools/source/debug/debug \ diff --git a/tools/source/datetime/datetimeutils.cxx b/tools/source/datetime/datetimeutils.cxx new file mode 100644 index 000000000000..512ae8230f11 --- /dev/null +++ b/tools/source/datetime/datetimeutils.cxx @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <tools/datetimeutils.hxx> +#include <rtl/strbuf.hxx> + + +/// Append the number as 2-digit when less than 10. +static void lcl_AppendTwoDigits( OStringBuffer &rBuffer, sal_Int32 nNum ) +{ + if ( nNum < 0 || nNum > 99 ) + { + rBuffer.append( "00" ); + return; + } + + if ( nNum < 10 ) + rBuffer.append( '0' ); + + rBuffer.append( nNum ); +} + +OString DateTimeToOString( const DateTime& rDateTime ) +{ + DateTime aInUTC( rDateTime ); +// HACK: this is correct according to the spec, but MSOffice believes everybody lives +// in UTC+0 when reading it back +// aInUTC.ConvertToUTC(); + + OStringBuffer aBuffer( 25 ); + aBuffer.append( sal_Int32( aInUTC.GetYear() ) ); + aBuffer.append( '-' ); + + lcl_AppendTwoDigits( aBuffer, aInUTC.GetMonth() ); + aBuffer.append( '-' ); + + lcl_AppendTwoDigits( aBuffer, aInUTC.GetDay() ); + aBuffer.append( 'T' ); + + lcl_AppendTwoDigits( aBuffer, aInUTC.GetHour() ); + aBuffer.append( ':' ); + + lcl_AppendTwoDigits( aBuffer, aInUTC.GetMin() ); + aBuffer.append( ':' ); + + lcl_AppendTwoDigits( aBuffer, aInUTC.GetSec() ); + aBuffer.append( 'Z' ); // we are in UTC + + return aBuffer.makeStringAndClear(); +} diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 45142af8e3c1..5ab452025009 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -34,6 +34,7 @@ #include <filter/msfilter/escherex.hxx> #include <comphelper/string.hxx> #include <tools/globname.hxx> +#include <tools/datetimeutils.hxx> #include <comphelper/classids.hxx> #include <comphelper/embeddedobjectcontainer.hxx> #include <sfx2/sfxbasemodel.hxx> @@ -152,7 +153,7 @@ static void lcl_putBorderProperty(std::stack<RTFParserState>& aStates, Id nId, R static OString lcl_DTTM22OString(long lDTTM) { - return msfilter::util::DateTimeToOString(msfilter::util::DTTM2DateTime(lDTTM)); + return DateTimeToOString(msfilter::util::DTTM2DateTime(lDTTM)); } static writerfilter::Reference<Properties>::Pointer_t lcl_getBookmarkProperties(int nPos, OUString& rString) |