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 "DateScaling.hxx"
22 #include <rtl/math.hxx>
23 #include <com/sun/star/chart/TimeUnit.hpp>
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
)
43 long nMonth
= rD
.GetMonth()+nMonthDistance
;
44 long nNewMonth
= nMonth
%12;
45 long nNewYear
= rD
.GetYear() + nMonth
/12;
46 if( nMonth
<= 0 || !nNewMonth
)
50 aRet
.SetMonth( sal_uInt16(nNewMonth
) );
51 aRet
.SetYear( sal_uInt16(nNewYear
) );
56 Date
DateHelper::GetDateSomeYearsAway( const Date
& rD
, long nYearDistance
)
59 aRet
.SetYear( static_cast<sal_uInt16
>(rD
.GetYear()+nYearDistance
) );
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
)
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
)
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
:
91 case ::com::sun::star::chart::TimeUnit::YEAR
:
95 case ::com::sun::star::chart::TimeUnit::MONTH
:
100 return aDate
- rNullDate
;
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */