summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-05-10 11:39:18 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-05-13 14:44:19 +0200
commit57dc0cbd8ebfe465f9e21a47c253a8437f8860a9 (patch)
tree3c545bb0702f5177b642af9df8ee69ea0acf62c5 /tools
parentb6652dae45a469bc0e357ff4755a92992b0856e9 (diff)
do less OString->OUString conversion in tools datetime functions
Change-Id: I93d012f32b8006019c431b8bf88ab9c7ffb4d3a0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167574 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Jenkins
Diffstat (limited to 'tools')
-rw-r--r--tools/source/datetime/datetimeutils.cxx23
1 files changed, 18 insertions, 5 deletions
diff --git a/tools/source/datetime/datetimeutils.cxx b/tools/source/datetime/datetimeutils.cxx
index 4c3b28d49dc6..345e18f4a721 100644
--- a/tools/source/datetime/datetimeutils.cxx
+++ b/tools/source/datetime/datetimeutils.cxx
@@ -9,10 +9,12 @@
#include <tools/datetimeutils.hxx>
#include <rtl/strbuf.hxx>
+#include <rtl/ustrbuf.hxx>
/// Append the number as 2-digit when less than 10.
-static void lcl_AppendTwoDigits( OStringBuffer &rBuffer, sal_Int32 nNum )
+template<class TStringBuffer>
+static void lcl_AppendTwoDigits( TStringBuffer &rBuffer, sal_Int32 nNum )
{
if ( nNum < 0 || nNum > 99 )
{
@@ -26,14 +28,15 @@ static void lcl_AppendTwoDigits( OStringBuffer &rBuffer, sal_Int32 nNum )
rBuffer.append( nNum );
}
-OString DateTimeToOString( const DateTime& rDateTime )
+template<class TString, class TStringBuffer>
+static TString DateTimeToStringImpl( const DateTime& rDateTime )
{
const 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 );
+ TStringBuffer aBuffer( 25 );
aBuffer.append( sal_Int32( aInUTC.GetYear() ) );
aBuffer.append( '-' );
@@ -55,15 +58,25 @@ OString DateTimeToOString( const DateTime& rDateTime )
return aBuffer.makeStringAndClear();
}
+OString DateTimeToOString( const DateTime& rDateTime )
+{
+ return DateTimeToStringImpl<OString,OStringBuffer>(rDateTime);
+}
+
+OUString DateTimeToOUString( const DateTime& rDateTime )
+{
+ return DateTimeToStringImpl<OUString,OUStringBuffer>(rDateTime);
+}
+
OString DateToOString( const Date& rDate )
{
tools::Time aTime( tools::Time::EMPTY );
return DateTimeToOString( DateTime( rDate, aTime ) );
}
-OString DateToDDMMYYYYOString( const Date& rDate )
+OUString DateToDDMMYYYYOUString( const Date& rDate )
{
- OStringBuffer aBuffer( 25 );
+ OUStringBuffer aBuffer( 25 );
lcl_AppendTwoDigits( aBuffer, rDate.GetDay() );
aBuffer.append( '/' );