Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / view / axes / DateHelper.cxx
blob046760436acd7524da01f91cd6781c105695d977
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, sal_Int32 nMonthDistance )
42 Date aRet(rD);
43 aRet.AddMonths( nMonthDistance );
44 return aRet;
47 Date DateHelper::GetDateSomeYearsAway( const Date& rD, sal_Int32 nYearDistance )
49 Date aRet(rD);
50 aRet.AddYears( static_cast<sal_Int16>(nYearDistance) );
51 return aRet;
54 bool DateHelper::IsLessThanOneMonthAway( const Date& rD1, const Date& rD2 )
56 Date aDMin( DateHelper::GetDateSomeMonthsAway( rD1, -1 ) );
57 Date aDMax( DateHelper::GetDateSomeMonthsAway( rD1, 1 ) );
59 return rD2 > aDMin && rD2 < aDMax;
62 bool DateHelper::IsLessThanOneYearAway( const Date& rD1, const Date& rD2 )
64 Date aDMin( DateHelper::GetDateSomeYearsAway( rD1, -1 ) );
65 Date aDMax( DateHelper::GetDateSomeYearsAway( rD1, 1 ) );
67 return rD2 > aDMin && rD2 < aDMax;
70 double DateHelper::RasterizeDateValue( double fValue, const Date& rNullDate, long TimeResolution )
72 Date aDate(rNullDate); aDate.AddDays(::rtl::math::approxFloor(fValue));
73 switch(TimeResolution)
75 case css::chart::TimeUnit::DAY:
76 break;
77 case css::chart::TimeUnit::YEAR:
78 aDate.SetMonth(1);
79 aDate.SetDay(1);
80 break;
81 case css::chart::TimeUnit::MONTH:
82 default:
83 aDate.SetDay(1);
84 break;
86 return aDate - rNullDate;
89 } //namespace chart
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */