tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / view / axes / DateHelper.cxx
blob4c4a96dce2f86f51ab73a3bd56c6deb3f7065d8c
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 <rtl/math.hxx>
22 #include <com/sun/star/chart/TimeUnit.hpp>
24 namespace chart
26 using namespace ::com::sun::star;
28 bool DateHelper::IsInSameYear( const Date& rD1, const Date& rD2 )
30 return rD1.GetYear() == rD2.GetYear();
33 bool DateHelper::IsInSameMonth( const Date& rD1, const Date& rD2 )
35 return (rD1.GetYear() == rD2.GetYear())
36 && (rD1.GetMonth() == rD2.GetMonth());
39 Date DateHelper::GetDateSomeMonthsAway( const Date& rD, sal_Int32 nMonthDistance )
41 Date aRet(rD);
42 aRet.AddMonths( nMonthDistance );
43 return aRet;
46 Date DateHelper::GetDateSomeYearsAway( const Date& rD, sal_Int32 nYearDistance )
48 Date aRet(rD);
49 aRet.AddYears( static_cast<sal_Int16>(nYearDistance) );
50 return aRet;
53 bool DateHelper::IsLessThanOneMonthAway( const Date& rD1, const Date& rD2 )
55 Date aDMin( DateHelper::GetDateSomeMonthsAway( rD1, -1 ) );
56 Date aDMax( DateHelper::GetDateSomeMonthsAway( rD1, 1 ) );
58 return rD2 > aDMin && rD2 < aDMax;
61 bool DateHelper::IsLessThanOneYearAway( const Date& rD1, const Date& rD2 )
63 Date aDMin( DateHelper::GetDateSomeYearsAway( rD1, -1 ) );
64 Date aDMax( DateHelper::GetDateSomeYearsAway( rD1, 1 ) );
66 return rD2 > aDMin && rD2 < aDMax;
69 double DateHelper::RasterizeDateValue( double fValue, const Date& rNullDate, tools::Long TimeResolution )
71 if (std::isnan(fValue))
72 return fValue;
74 Date aDate(rNullDate); aDate.AddDays(::rtl::math::approxFloor(fValue));
75 switch(TimeResolution)
77 case css::chart::TimeUnit::DAY:
78 break;
79 case css::chart::TimeUnit::YEAR:
80 aDate.SetMonth(1);
81 aDate.SetDay(1);
82 break;
83 case css::chart::TimeUnit::MONTH:
84 default:
85 aDate.SetDay(1);
86 break;
88 return aDate - rNullDate;
91 } //namespace chart
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */