Coverage Report

Created: 2026-09-28 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/time/daycounters/simpledaycounter.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2003 RiskMap srl
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
#include <ql/time/daycounters/simpledaycounter.hpp>
21
#include <ql/time/daycounters/thirty360.hpp>
22
23
namespace QuantLib {
24
25
    namespace { DayCounter fallback = Thirty360(Thirty360::BondBasis); }
26
27
    Date::serial_type SimpleDayCounter::Impl::dayCount(const Date& d1,
28
0
                                                       const Date& d2) const {
29
0
        return fallback.dayCount(d1,d2);
30
0
    }
31
32
    Time SimpleDayCounter::Impl::yearFraction(const Date& d1,
33
                                              const Date& d2,
34
                                              const Date&,
35
0
                                              const Date&) const {
36
0
        Day dm1 = d1.dayOfMonth(),
37
0
            dm2 = d2.dayOfMonth();
38
39
0
        if (dm1 == dm2 ||
40
            // e.g., Aug 30 -> Feb 28 ?
41
0
            (dm1 > dm2 && Date::isEndOfMonth(d2)) ||
42
            // e.g., Feb 28 -> Aug 30 ?
43
0
            (dm1 < dm2 && Date::isEndOfMonth(d1))) {
44
45
0
            return (d2.year()-d1.year()) +
46
0
                (Integer(d2.month())-Integer(d1.month()))/12.0;
47
48
0
        } else {
49
0
            return fallback.yearFraction(d1,d2);
50
0
        }
51
0
    }
52
53
}
54