LCOV - code coverage report
Current view: top level - chart2/source/view/axes - DateHelper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 45 0.0 %
Date: 2014-04-14 Functions: 0 7 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             :  * 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             : namespace chart
      26             : {
      27             : using namespace ::com::sun::star;
      28             : 
      29           0 : bool DateHelper::IsInSameYear( const Date& rD1, const Date& rD2 )
      30             : {
      31           0 :     return rD1.GetYear() == rD2.GetYear();
      32             : }
      33             : 
      34           0 : bool DateHelper::IsInSameMonth( const Date& rD1, const Date& rD2 )
      35             : {
      36           0 :     return (rD1.GetYear() == rD2.GetYear())
      37           0 :         && (rD1.GetMonth() == rD2.GetMonth());
      38             : }
      39             : 
      40           0 : Date DateHelper::GetDateSomeMonthsAway( const Date& rD, long nMonthDistance )
      41             : {
      42           0 :     Date aRet(rD);
      43           0 :     long nMonth = rD.GetMonth()+nMonthDistance;
      44           0 :     long nNewMonth = nMonth%12;
      45           0 :     long nNewYear = rD.GetYear() + nMonth/12;
      46           0 :     if( nMonth <= 0 || !nNewMonth )
      47           0 :         nNewYear--;
      48           0 :     if( nNewMonth <= 0 )
      49           0 :         nNewMonth += 12;
      50           0 :     aRet.SetMonth( sal_uInt16(nNewMonth) );
      51           0 :     aRet.SetYear( sal_uInt16(nNewYear) );
      52           0 :     aRet.Normalize();
      53           0 :     return aRet;
      54             : }
      55             : 
      56           0 : Date DateHelper::GetDateSomeYearsAway( const Date& rD, long nYearDistance )
      57             : {
      58           0 :     Date aRet(rD);
      59           0 :     aRet.SetYear( static_cast<sal_uInt16>(rD.GetYear()+nYearDistance) );
      60           0 :     aRet.Normalize();
      61           0 :     return aRet;
      62             : }
      63             : 
      64           0 : bool DateHelper::IsLessThanOneMonthAway( const Date& rD1, const Date& rD2 )
      65             : {
      66           0 :     Date aDMin( DateHelper::GetDateSomeMonthsAway( rD1, -1 ) );
      67           0 :     Date aDMax( DateHelper::GetDateSomeMonthsAway( rD1, 1 ) );
      68             : 
      69           0 :     if( rD2 > aDMin && rD2 < aDMax )
      70           0 :         return true;
      71           0 :     return false;
      72             : }
      73             : 
      74           0 : bool DateHelper::IsLessThanOneYearAway( const Date& rD1, const Date& rD2 )
      75             : {
      76           0 :     Date aDMin( DateHelper::GetDateSomeYearsAway( rD1, -1 ) );
      77           0 :     Date aDMax( DateHelper::GetDateSomeYearsAway( rD1, 1 ) );
      78             : 
      79           0 :     if( rD2 > aDMin && rD2 < aDMax )
      80           0 :         return true;
      81           0 :     return false;
      82             : }
      83             : 
      84           0 : double DateHelper::RasterizeDateValue( double fValue, const Date& rNullDate, long TimeResolution )
      85             : {
      86           0 :     Date aDate(rNullDate); aDate += static_cast<long>(::rtl::math::approxFloor(fValue));
      87           0 :     switch(TimeResolution)
      88             :     {
      89             :         case ::com::sun::star::chart::TimeUnit::DAY:
      90           0 :             break;
      91             :         case ::com::sun::star::chart::TimeUnit::YEAR:
      92           0 :             aDate.SetMonth(1);
      93           0 :             aDate.SetDay(1);
      94           0 :             break;
      95             :         case ::com::sun::star::chart::TimeUnit::MONTH:
      96             :         default:
      97           0 :             aDate.SetDay(1);
      98           0 :             break;
      99             :     }
     100           0 :     return aDate - rNullDate;
     101             : }
     102             : 
     103             : } //namespace chart
     104             : 
     105             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10