LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/view/axes - DateHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 5 45 11.1 %
Date: 2012-12-27 Functions: 1 7 14.3 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "DateHelper.hxx"
      21             : #include "DateScaling.hxx"
      22             : #include <rtl/math.hxx>
      23             : #include <com/sun/star/chart/TimeUnit.hpp>
      24             : 
      25             : //.............................................................................
      26             : namespace chart
      27             : {
      28             : //.............................................................................
      29             : using namespace ::com::sun::star;
      30             : 
      31           0 : bool DateHelper::IsInSameYear( const Date& rD1, const Date& rD2 )
      32             : {
      33           0 :     return rD1.GetYear() == rD2.GetYear();
      34             : }
      35             : 
      36           0 : bool DateHelper::IsInSameMonth( const Date& rD1, const Date& rD2 )
      37             : {
      38           0 :     return (rD1.GetYear() == rD2.GetYear())
      39           0 :         && (rD1.GetMonth() == rD2.GetMonth());
      40             : }
      41             : 
      42           0 : Date DateHelper::GetDateSomeMonthsAway( const Date& rD, long nMonthDistance )
      43             : {
      44           0 :     Date aRet(rD);
      45           0 :     long nMonth = rD.GetMonth()+nMonthDistance;
      46           0 :     long nNewMonth = nMonth%12;
      47           0 :     long nNewYear = rD.GetYear() + nMonth/12;
      48           0 :     if( nMonth <= 0 || !nNewMonth )
      49           0 :         nNewYear--;
      50           0 :     if( nNewMonth <= 0 )
      51           0 :         nNewMonth += 12;
      52           0 :     aRet.SetMonth( sal_uInt16(nNewMonth) );
      53           0 :     aRet.SetYear( sal_uInt16(nNewYear) );
      54           0 :     aRet.Normalize();
      55           0 :     return aRet;
      56             : }
      57             : 
      58           0 : Date DateHelper::GetDateSomeYearsAway( const Date& rD, long nYearDistance )
      59             : {
      60           0 :     Date aRet(rD);
      61           0 :     aRet.SetYear( static_cast<sal_uInt16>(rD.GetYear()+nYearDistance) );
      62           0 :     aRet.Normalize();
      63           0 :     return aRet;
      64             : }
      65             : 
      66           0 : bool DateHelper::IsLessThanOneMonthAway( const Date& rD1, const Date& rD2 )
      67             : {
      68           0 :     Date aDMin( DateHelper::GetDateSomeMonthsAway( rD1, -1 ) );
      69           0 :     Date aDMax( DateHelper::GetDateSomeMonthsAway( rD1, 1 ) );
      70             : 
      71           0 :     if( rD2 > aDMin && rD2 < aDMax )
      72           0 :         return true;
      73           0 :     return false;
      74             : }
      75             : 
      76           0 : bool DateHelper::IsLessThanOneYearAway( const Date& rD1, const Date& rD2 )
      77             : {
      78           0 :     Date aDMin( DateHelper::GetDateSomeYearsAway( rD1, -1 ) );
      79           0 :     Date aDMax( DateHelper::GetDateSomeYearsAway( rD1, 1 ) );
      80             : 
      81           0 :     if( rD2 > aDMin && rD2 < aDMax )
      82           0 :         return true;
      83           0 :     return false;
      84             : }
      85             : 
      86         492 : double DateHelper::RasterizeDateValue( double fValue, const Date& rNullDate, long TimeResolution )
      87             : {
      88         492 :     Date aDate(rNullDate); aDate += static_cast<long>(::rtl::math::approxFloor(fValue));
      89         492 :     switch(TimeResolution)
      90             :     {
      91             :         case ::com::sun::star::chart::TimeUnit::DAY:
      92         492 :             break;
      93             :         case ::com::sun::star::chart::TimeUnit::YEAR:
      94           0 :             aDate.SetMonth(1);
      95           0 :             aDate.SetDay(1);
      96           0 :             break;
      97             :         case ::com::sun::star::chart::TimeUnit::MONTH:
      98             :         default:
      99           0 :             aDate.SetDay(1);
     100           0 :             break;
     101             :     }
     102         492 :     return aDate - rNullDate;
     103             : }
     104             : 
     105             : //.............................................................................
     106             : } //namespace chart
     107             : //.............................................................................
     108             : 
     109             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10