1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
)
42 aRet
.AddMonths( nMonthDistance
);
46 Date
DateHelper::GetDateSomeYearsAway( const Date
& rD
, sal_Int32 nYearDistance
)
49 aRet
.AddYears( static_cast<sal_Int16
>(nYearDistance
) );
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
))
74 Date
aDate(rNullDate
); aDate
.AddDays(::rtl::math::approxFloor(fValue
));
75 switch(TimeResolution
)
77 case css::chart::TimeUnit::DAY
:
79 case css::chart::TimeUnit::YEAR
:
83 case css::chart::TimeUnit::MONTH
:
88 return aDate
- rNullDate
;
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */