fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / view / axes / DateHelper.cxx
blob5e5267de5b9ec5d041cf00cddb20d496bdb6a9bd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "DateHelper.hxx"
21 #include "DateScaling.hxx"
22 #include <rtl/math.hxx>
23 #include <com/sun/star/chart/TimeUnit.hpp>
25 namespace chart
27 using namespace ::com::sun::star;
29 bool DateHelper::IsInSameYear( const Date& rD1, const Date& rD2 )
31 return rD1.GetYear() == rD2.GetYear();
34 bool DateHelper::IsInSameMonth( const Date& rD1, const Date& rD2 )
36 return (rD1.GetYear() == rD2.GetYear())
37 && (rD1.GetMonth() == rD2.GetMonth());
40 Date DateHelper::GetDateSomeMonthsAway( const Date& rD, long nMonthDistance )
42 Date aRet(rD);
43 long nMonth = rD.GetMonth()+nMonthDistance;
44 long nNewMonth = nMonth%12;
45 long nNewYear = rD.GetYear() + nMonth/12;
46 if( nMonth <= 0 || !nNewMonth )
47 nNewYear--;
48 if( nNewMonth <= 0 )
49 nNewMonth += 12;
50 aRet.SetMonth( sal_uInt16(nNewMonth) );
51 aRet.SetYear( sal_uInt16(nNewYear) );
52 aRet.Normalize();
53 return aRet;
56 Date DateHelper::GetDateSomeYearsAway( const Date& rD, long nYearDistance )
58 Date aRet(rD);
59 aRet.SetYear( static_cast<sal_uInt16>(rD.GetYear()+nYearDistance) );
60 aRet.Normalize();
61 return aRet;
64 bool DateHelper::IsLessThanOneMonthAway( const Date& rD1, const Date& rD2 )
66 Date aDMin( DateHelper::GetDateSomeMonthsAway( rD1, -1 ) );
67 Date aDMax( DateHelper::GetDateSomeMonthsAway( rD1, 1 ) );
69 if( rD2 > aDMin && rD2 < aDMax )
70 return true;
71 return false;
74 bool DateHelper::IsLessThanOneYearAway( const Date& rD1, const Date& rD2 )
76 Date aDMin( DateHelper::GetDateSomeYearsAway( rD1, -1 ) );
77 Date aDMax( DateHelper::GetDateSomeYearsAway( rD1, 1 ) );
79 if( rD2 > aDMin && rD2 < aDMax )
80 return true;
81 return false;
84 double DateHelper::RasterizeDateValue( double fValue, const Date& rNullDate, long TimeResolution )
86 Date aDate(rNullDate); aDate += static_cast<long>(::rtl::math::approxFloor(fValue));
87 switch(TimeResolution)
89 case ::com::sun::star::chart::TimeUnit::DAY:
90 break;
91 case ::com::sun::star::chart::TimeUnit::YEAR:
92 aDate.SetMonth(1);
93 aDate.SetDay(1);
94 break;
95 case ::com::sun::star::chart::TimeUnit::MONTH:
96 default:
97 aDate.SetDay(1);
98 break;
100 return aDate - rNullDate;
103 } //namespace chart
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */