summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAdam Co <rattles2013@gmail.com>2013-11-26 13:56:46 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-11-26 14:02:02 +0100
commit8d7cb7773dafda969c22bb9cca658bf1c677798d (patch)
tree18d9efda9a959322f98d9fd69e77615fdebf2036 /tools
parentfc708d6286e184d7f1b63e4a334d5aa1c7959516 (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 Change-Id: I0ceb9a5cc26103a6cb36d7765a717770ec3fbe7d
Diffstat (limited to 'tools')
-rw-r--r--tools/Library_tl.mk1
-rw-r--r--tools/source/datetime/datetimeutils.cxx56
2 files changed, 57 insertions, 0 deletions
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk
index db2360b077f4..93f32c7cc303 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();
+}