Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/time/calendars/japan.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2000-2003 RiskMap srl
5
 Copyright (C) 2003 Kawanishi Tomoya
6
 Copyright (C) 2016, 2019, 2020 Eisuke Tani
7
8
 This file is part of QuantLib, a free-software/open-source library
9
 for financial quantitative analysts and developers - http://quantlib.org/
10
11
 QuantLib is free software: you can redistribute it and/or modify it
12
 under the terms of the QuantLib license.  You should have received a
13
 copy of the license along with this program; if not, please email
14
 <quantlib-dev@lists.sf.net>. The license is also available online at
15
 <https://www.quantlib.org/license.shtml>.
16
17
 This program is distributed in the hope that it will be useful, but WITHOUT
18
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 FOR A PARTICULAR PURPOSE.  See the license for more details.
20
*/
21
22
#include <ql/time/calendars/japan.hpp>
23
24
namespace QuantLib {
25
26
0
    Japan::Japan() {
27
        // all calendar instances share the same implementation instance
28
0
        static ext::shared_ptr<Calendar::Impl> impl(new Japan::Impl);
29
0
        impl_ = impl;
30
0
    }
31
32
0
    bool Japan::Impl::isWeekend(Weekday w) const {
33
0
        return w == Saturday || w == Sunday;
34
0
    }
35
36
0
    bool Japan::Impl::isBusinessDay(const Date& date) const {
37
0
        Weekday w = date.weekday();
38
0
        Day d = date.dayOfMonth();
39
0
        Month m = date.month();
40
0
        Year y = date.year();
41
        // equinox calculation
42
0
        const Time exact_vernal_equinox_time = 20.69115;
43
0
        const Time exact_autumnal_equinox_time = 23.09;
44
0
        const Time diff_per_year = 0.242194;
45
0
        const Time moving_amount = (y-2000)*diff_per_year;
46
0
        Integer number_of_leap_years = (y-2000)/4+(y-2000)/100-(y-2000)/400;
47
0
        Day ve =    // vernal equinox day
48
0
            Day(exact_vernal_equinox_time
49
0
                + moving_amount - number_of_leap_years);
50
0
        Day ae =    // autumnal equinox day
51
0
            Day(exact_autumnal_equinox_time
52
0
                + moving_amount - number_of_leap_years);
53
        // checks
54
0
        if (isWeekend(w)
55
            // New Year's Day
56
0
            || (d == 1  && m == January)
57
            // Bank Holiday
58
0
            || (d == 2  && m == January)
59
            // Bank Holiday
60
0
            || (d == 3  && m == January)
61
            // Coming of Age Day (2nd Monday in January),
62
            // was January 15th until 2000
63
0
            || (w == Monday && (d >= 8 && d <= 14) && m == January
64
0
                && y >= 2000)
65
0
            || ((d == 15 || (d == 16 && w == Monday)) && m == January
66
0
                && y < 2000)
67
            // National Foundation Day
68
0
            || ((d == 11 || (d == 12 && w == Monday)) && m == February)
69
            // Emperor's Birthday (Emperor Naruhito)
70
0
            || ((d == 23 || (d == 24 && w == Monday)) && m == February
71
0
                && y >= 2020)
72
            // Emperor's Birthday (Emperor Akihito)
73
0
            || ((d == 23 || (d == 24 && w == Monday)) && m == December
74
0
                && (y >= 1989 && y < 2019))
75
            // Vernal Equinox
76
0
            || ((d == ve || (d == ve+1 && w == Monday)) && m == March)
77
            // Greenery Day
78
0
            || ((d == 29 || (d == 30 && w == Monday)) && m == April)
79
            // Constitution Memorial Day
80
0
            || (d == 3  && m == May)
81
            // Holiday for a Nation
82
0
            || (d == 4  && m == May)
83
            // Children's Day
84
0
            || (d == 5  && m == May)
85
            // any of the three above observed later if on Saturday or Sunday
86
0
            || (d == 6 && m == May
87
0
                && (w == Monday || w == Tuesday || w == Wednesday))
88
            // Marine Day (3rd Monday in July),
89
            // was July 20th until 2003, not a holiday before 1996,
90
            // July 23rd in 2020 due to Olympics games
91
            // July 22nd in 2021 due to Olympics games
92
0
            || (w == Monday && (d >= 15 && d <= 21) && m == July
93
0
                && ((y >= 2003 && y < 2020) || y >= 2022))
94
0
            || ((d == 20 || (d == 21 && w == Monday)) && m == July
95
0
                && y >= 1996 && y < 2003)
96
0
            || (d == 23 && m == July && y == 2020)
97
0
            || (d == 22 && m == July && y == 2021)
98
            // Mountain Day
99
            // (moved in 2020 due to Olympics games)
100
            // (moved in 2021 due to Olympics games)
101
0
            || ((d == 11 || (d == 12 && w == Monday)) && m == August
102
0
                && ((y >= 2016 && y < 2020) || y >= 2022))
103
0
            || (d == 10 && m == August && y == 2020)
104
0
            || (d == 9 && m == August && y == 2021)
105
            // Respect for the Aged Day (3rd Monday in September),
106
            // was September 15th until 2003
107
0
            || (w == Monday && (d >= 15 && d <= 21) && m == September
108
0
                && y >= 2003)
109
0
            || ((d == 15 || (d == 16 && w == Monday)) && m == September
110
0
                && y < 2003)
111
            // If a single day falls between Respect for the Aged Day
112
            // and the Autumnal Equinox, it is holiday
113
0
            || (w == Tuesday && d+1 == ae && d >= 16 && d <= 22
114
0
                && m == September && y >= 2003)
115
            // Autumnal Equinox
116
0
            || ((d == ae || (d == ae+1 && w == Monday)) && m == September)
117
            // Health and Sports Day (2nd Monday in October),
118
            // was October 10th until 2000,
119
            // July 24th in 2020 due to Olympics games
120
            // July 23rd in 2021 due to Olympics games
121
0
            || (w == Monday && (d >= 8 && d <= 14) && m == October
122
0
                && ((y >= 2000 && y < 2020) || y >= 2022))
123
0
            || ((d == 10 || (d == 11 && w == Monday)) && m == October
124
0
                && y < 2000)
125
0
            || (d == 24 && m == July && y == 2020)
126
0
            || (d == 23 && m == July && y == 2021)
127
            // National Culture Day
128
0
            || ((d == 3  || (d == 4 && w == Monday)) && m == November)
129
            // Labor Thanksgiving Day
130
0
            || ((d == 23 || (d == 24 && w == Monday)) && m == November)
131
            // Bank Holiday
132
0
            || (d == 31 && m == December)
133
            // one-shot holidays
134
            // Marriage of Prince Akihito
135
0
            || (d == 10 && m == April && y == 1959)
136
            // Rites of Imperial Funeral
137
0
            || (d == 24 && m == February && y == 1989)
138
            // Enthronement Ceremony (Emperor Akihito)
139
0
            || (d == 12 && m == November && y == 1990)
140
            // Marriage of Prince Naruhito
141
0
            || (d == 9 && m == June && y == 1993)
142
            // Special holiday based on Japanese public holidays law
143
0
            || (d == 30 && m == April && y == 2019)
144
            // Enthronement Day (Emperor Naruhito)
145
0
            || (d == 1 && m == May && y == 2019)
146
            // Special holiday based on Japanese public holidays law
147
0
            || (d == 2 && m == May && y == 2019)
148
            // Enthronement Ceremony (Emperor Naruhito)
149
0
            || (d == 22 && m == October && y == 2019))
150
0
            return false; // NOLINT(readability-simplify-boolean-expr)
151
0
        return true;
152
0
    }
153
154
}