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