LCOV - code coverage report
Current view: top level - tools/source/datetime - datetimeutils.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 25 34 73.5 %
Date: 2014-04-11 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  */
       9             : 
      10             : #include <tools/datetimeutils.hxx>
      11             : #include <rtl/strbuf.hxx>
      12             : 
      13             : 
      14             : /// Append the number as 2-digit when less than 10.
      15         195 : static void lcl_AppendTwoDigits( OStringBuffer &rBuffer, sal_Int32 nNum )
      16             : {
      17         195 :     if ( nNum < 0 || nNum > 99 )
      18             :     {
      19           0 :         rBuffer.append( "00" );
      20         195 :         return;
      21             :     }
      22             : 
      23         195 :     if ( nNum < 10 )
      24         136 :         rBuffer.append( '0' );
      25             : 
      26         195 :     rBuffer.append( nNum );
      27             : }
      28             : 
      29          39 : OString DateTimeToOString( const DateTime& rDateTime )
      30             : {
      31          39 :     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();
      35             : 
      36          39 :     OStringBuffer aBuffer( 25 );
      37          39 :     aBuffer.append( sal_Int32( aInUTC.GetYear() ) );
      38          39 :     aBuffer.append( '-' );
      39             : 
      40          39 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetMonth() );
      41          39 :     aBuffer.append( '-' );
      42             : 
      43          39 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetDay() );
      44          39 :     aBuffer.append( 'T' );
      45             : 
      46          39 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetHour() );
      47          39 :     aBuffer.append( ':' );
      48             : 
      49          39 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetMin() );
      50          39 :     aBuffer.append( ':' );
      51             : 
      52          39 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetSec() );
      53          39 :     aBuffer.append( 'Z' ); // we are in UTC
      54             : 
      55          39 :     return aBuffer.makeStringAndClear();
      56             : }
      57             : 
      58           1 : OString DateToOString( const Date& rDate )
      59             : {
      60           1 :     Time aTime( Time::EMPTY );
      61           1 :     return DateTimeToOString( DateTime( rDate, aTime ) );
      62             : }
      63             : 
      64           0 : OString DateToDDMMYYYYOString( const Date& rDate )
      65             : {
      66           0 :     OStringBuffer aBuffer( 25 );
      67           0 :     lcl_AppendTwoDigits( aBuffer, rDate.GetDay() );
      68           0 :     aBuffer.append( '/' );
      69             : 
      70           0 :     lcl_AppendTwoDigits( aBuffer, rDate.GetMonth() );
      71           0 :     aBuffer.append( '/' );
      72             : 
      73           0 :     aBuffer.append( sal_Int32( rDate.GetYear() ) );
      74             : 
      75           0 :     return aBuffer.makeStringAndClear();
      76             : }

Generated by: LCOV version 1.10