LibreOffice Module chart2 (master) 1
DateHelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <DateHelper.hxx>
21#include <rtl/math.hxx>
22#include <com/sun/star/chart/TimeUnit.hpp>
23
24namespace chart
25{
26using namespace ::com::sun::star;
27
28bool DateHelper::IsInSameYear( const Date& rD1, const Date& rD2 )
29{
30 return rD1.GetYear() == rD2.GetYear();
31}
32
33bool DateHelper::IsInSameMonth( const Date& rD1, const Date& rD2 )
34{
35 return (rD1.GetYear() == rD2.GetYear())
36 && (rD1.GetMonth() == rD2.GetMonth());
37}
38
39Date DateHelper::GetDateSomeMonthsAway( const Date& rD, sal_Int32 nMonthDistance )
40{
41 Date aRet(rD);
42 aRet.AddMonths( nMonthDistance );
43 return aRet;
44}
45
46Date DateHelper::GetDateSomeYearsAway( const Date& rD, sal_Int32 nYearDistance )
47{
48 Date aRet(rD);
49 aRet.AddYears( static_cast<sal_Int16>(nYearDistance) );
50 return aRet;
51}
52
53bool DateHelper::IsLessThanOneMonthAway( const Date& rD1, const Date& rD2 )
54{
55 Date aDMin( DateHelper::GetDateSomeMonthsAway( rD1, -1 ) );
56 Date aDMax( DateHelper::GetDateSomeMonthsAway( rD1, 1 ) );
57
58 return rD2 > aDMin && rD2 < aDMax;
59}
60
61bool DateHelper::IsLessThanOneYearAway( const Date& rD1, const Date& rD2 )
62{
63 Date aDMin( DateHelper::GetDateSomeYearsAway( rD1, -1 ) );
64 Date aDMax( DateHelper::GetDateSomeYearsAway( rD1, 1 ) );
65
66 return rD2 > aDMin && rD2 < aDMax;
67}
68
69double DateHelper::RasterizeDateValue( double fValue, const Date& rNullDate, tools::Long TimeResolution )
70{
71 if (std::isnan(fValue))
72 return fValue;
73
74 Date aDate(rNullDate); aDate.AddDays(::rtl::math::approxFloor(fValue));
75 switch(TimeResolution)
76 {
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;
87 }
88 return aDate - rNullDate;
89}
90
91} //namespace chart
92
93/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void AddDays(sal_Int32 nAddDays)
sal_Int16 GetYear() const
void AddYears(sal_Int16 nAddYears)
void SetMonth(sal_uInt16 nNewMonth)
void AddMonths(sal_Int32 nAddMonths)
void SetDay(sal_uInt16 nNewDay)
sal_uInt16 GetMonth() const
static bool IsInSameMonth(const Date &rD1, const Date &rD2)
Definition: DateHelper.cxx:33
static Date GetDateSomeYearsAway(const Date &rD, sal_Int32 nYearDistance)
Definition: DateHelper.cxx:46
static bool IsInSameYear(const Date &rD1, const Date &rD2)
Definition: DateHelper.cxx:28
static Date GetDateSomeMonthsAway(const Date &rD, sal_Int32 nMonthDistance)
Definition: DateHelper.cxx:39
static double RasterizeDateValue(double fValue, const Date &rNullDate, tools::Long TimeResolution)
Definition: DateHelper.cxx:69
static bool IsLessThanOneYearAway(const Date &rD1, const Date &rD2)
Definition: DateHelper.cxx:61
static bool IsLessThanOneMonthAway(const Date &rD1, const Date &rD2)
Definition: DateHelper.cxx:53
long Long