LCOV - code coverage report
Current view: top level - tools/source/datetime - datetimeutils.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 25 34 73.5 %
Date: 2015-06-13 12:38:46 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         525 : static void lcl_AppendTwoDigits( OStringBuffer &rBuffer, sal_Int32 nNum )
      16             : {
      17         525 :     if ( nNum < 0 || nNum > 99 )
      18             :     {
      19           0 :         rBuffer.append( "00" );
      20         525 :         return;
      21             :     }
      22             : 
      23         525 :     if ( nNum < 10 )
      24         243 :         rBuffer.append( '0' );
      25             : 
      26         525 :     rBuffer.append( nNum );
      27             : }
      28             : 
      29         105 : OString DateTimeToOString( const DateTime& rDateTime )
      30             : {
      31         105 :     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         105 :     OStringBuffer aBuffer( 25 );
      37         105 :     aBuffer.append( sal_Int32( aInUTC.GetYear() ) );
      38         105 :     aBuffer.append( '-' );
      39             : 
      40         105 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetMonth() );
      41         105 :     aBuffer.append( '-' );
      42             : 
      43         105 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetDay() );
      44         105 :     aBuffer.append( 'T' );
      45             : 
      46         105 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetHour() );
      47         105 :     aBuffer.append( ':' );
      48             : 
      49         105 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetMin() );
      50         105 :     aBuffer.append( ':' );
      51             : 
      52         105 :     lcl_AppendTwoDigits( aBuffer, aInUTC.GetSec() );
      53         105 :     aBuffer.append( 'Z' ); // we are in UTC
      54             : 
      55         105 :     return aBuffer.makeStringAndClear();
      56             : }
      57             : 
      58           3 : OString DateToOString( const Date& rDate )
      59             : {
      60           3 :     tools::Time aTime( tools::Time::EMPTY );
      61           3 :     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.11