1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <tools/datetimeutils.hxx>
11 #include <rtl/strbuf.hxx>
14 /// Append the number as 2-digit when less than 10.
15 static void lcl_AppendTwoDigits( OStringBuffer
&rBuffer
, sal_Int32 nNum
)
17 if ( nNum
< 0 || nNum
> 99 )
19 rBuffer
.append( "00" );
24 rBuffer
.append( '0' );
26 rBuffer
.append( nNum
);
29 OString
DateTimeToOString( const DateTime
& rDateTime
)
31 DateTime
aInUTC( rDateTime
);
32 // HACK: this is correct according to the spec, but MSOffice believes everybody lives
33 // in UTC+0 when reading it back
34 // aInUTC.ConvertToUTC();
36 OStringBuffer
aBuffer( 25 );
37 aBuffer
.append( sal_Int32( aInUTC
.GetYear() ) );
38 aBuffer
.append( '-' );
40 lcl_AppendTwoDigits( aBuffer
, aInUTC
.GetMonth() );
41 aBuffer
.append( '-' );
43 lcl_AppendTwoDigits( aBuffer
, aInUTC
.GetDay() );
44 aBuffer
.append( 'T' );
46 lcl_AppendTwoDigits( aBuffer
, aInUTC
.GetHour() );
47 aBuffer
.append( ':' );
49 lcl_AppendTwoDigits( aBuffer
, aInUTC
.GetMin() );
50 aBuffer
.append( ':' );
52 lcl_AppendTwoDigits( aBuffer
, aInUTC
.GetSec() );
53 aBuffer
.append( 'Z' ); // we are in UTC
55 return aBuffer
.makeStringAndClear();
58 OString
DateToOString( const Date
& rDate
)
60 tools::Time
aTime( tools::Time::EMPTY
);
61 return DateTimeToOString( DateTime( rDate
, aTime
) );
64 OString
DateToDDMMYYYYOString( const Date
& rDate
)
66 OStringBuffer
aBuffer( 25 );
67 lcl_AppendTwoDigits( aBuffer
, rDate
.GetDay() );
68 aBuffer
.append( '/' );
70 lcl_AppendTwoDigits( aBuffer
, rDate
.GetMonth() );
71 aBuffer
.append( '/' );
73 aBuffer
.append( sal_Int32( rDate
.GetYear() ) );
75 return aBuffer
.makeStringAndClear();