Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/chart2/source/view/axes/DateHelper.cxx
Line
Count
Source
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
24
namespace chart
25
{
26
using namespace ::com::sun::star;
27
28
bool DateHelper::IsInSameYear( const Date& rD1, const Date& rD2 )
29
0
{
30
0
    return rD1.GetYear() == rD2.GetYear();
31
0
}
32
33
bool DateHelper::IsInSameMonth( const Date& rD1, const Date& rD2 )
34
0
{
35
0
    return (rD1.GetYear() == rD2.GetYear())
36
0
        && (rD1.GetMonth() == rD2.GetMonth());
37
0
}
38
39
Date DateHelper::GetDateSomeMonthsAway( const Date& rD, sal_Int32 nMonthDistance )
40
0
{
41
0
    Date aRet(rD);
42
0
    aRet.AddMonths( nMonthDistance );
43
0
    return aRet;
44
0
}
45
46
Date DateHelper::GetDateSomeYearsAway( const Date& rD, sal_Int32 nYearDistance )
47
0
{
48
0
    Date aRet(rD);
49
0
    aRet.AddYears( static_cast<sal_Int16>(nYearDistance) );
50
0
    return aRet;
51
0
}
52
53
bool DateHelper::IsLessThanOneMonthAway( const Date& rD1, const Date& rD2 )
54
0
{
55
0
    Date aDMin( DateHelper::GetDateSomeMonthsAway( rD1, -1 ) );
56
0
    Date aDMax( DateHelper::GetDateSomeMonthsAway( rD1, 1 ) );
57
58
0
    return rD2 > aDMin && rD2 < aDMax;
59
0
}
60
61
bool DateHelper::IsLessThanOneYearAway( const Date& rD1, const Date& rD2 )
62
0
{
63
0
    Date aDMin( DateHelper::GetDateSomeYearsAway( rD1, -1 ) );
64
0
    Date aDMax( DateHelper::GetDateSomeYearsAway( rD1, 1 ) );
65
66
0
    return rD2 > aDMin && rD2 < aDMax;
67
0
}
68
69
double DateHelper::RasterizeDateValue( double fValue, const Date& rNullDate, tools::Long TimeResolution )
70
0
{
71
0
    if (std::isnan(fValue))
72
0
        return fValue;
73
74
0
    Date aDate(rNullDate); aDate.AddDays(::rtl::math::approxFloor(fValue));
75
0
    switch(TimeResolution)
76
0
    {
77
0
        case css::chart::TimeUnit::DAY:
78
0
            break;
79
0
        case css::chart::TimeUnit::YEAR:
80
0
            aDate.SetMonth(1);
81
0
            aDate.SetDay(1);
82
0
            break;
83
0
        case css::chart::TimeUnit::MONTH:
84
0
        default:
85
0
            aDate.SetDay(1);
86
0
            break;
87
0
    }
88
0
    return aDate - rNullDate;
89
0
}
90
91
} //namespace chart
92
93
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */