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