Coverage Report

Created: 2025-08-05 06:45

/src/quantlib/ql/time/calendars/newzealand.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2000, 2001, 2002, 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
 <http://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/calendars/newzealand.hpp>
21
22
namespace QuantLib {
23
24
0
    bool NewZealand::CommonImpl::isBusinessDay(const Date& date) const {
25
0
        Weekday w = date.weekday();
26
0
        Day d = date.dayOfMonth(), dd = date.dayOfYear();
27
0
        Month m = date.month();
28
0
        Year y = date.year();
29
0
        Day em = easterMonday(y);
30
0
        if (isWeekend(w)
31
            // New Year's Day (possibly moved to Monday or Tuesday)
32
0
            || ((d == 1 || (d == 3 && (w == Monday || w == Tuesday))) &&
33
0
                m == January)
34
            // Day after New Year's Day (possibly moved to Mon or Tuesday)
35
0
            || ((d == 2 || (d == 4 && (w == Monday || w == Tuesday))) &&
36
0
                m == January)
37
            // Waitangi Day. February 6th (possibly moved to Monday since 2013)
38
0
            || (d == 6 && m == February)
39
0
            || ((d == 7 || d == 8) && w == Monday && m == February && y > 2013)
40
            // Good Friday
41
0
            || (dd == em-3)
42
            // Easter Monday
43
0
            || (dd == em)
44
            // ANZAC Day. April 25th (possibly moved to Monday since 2013) 
45
0
            || (d == 25 && m == April)
46
0
            || ((d == 26 || d == 27) && w == Monday && m == April && y > 2013)
47
            // Queen's Birthday, first Monday in June
48
0
            || (d <= 7 && w == Monday && m == June)
49
            // Labour Day, fourth Monday in October
50
0
            || ((d >= 22 && d <= 28) && w == Monday && m == October)
51
            // Christmas, December 25th (possibly Monday or Tuesday)
52
0
            || ((d == 25 || (d == 27 && (w == Monday || w == Tuesday)))
53
0
                && m == December)
54
            // Boxing Day, December 26th (possibly Monday or Tuesday)
55
0
            || ((d == 26 || (d == 28 && (w == Monday || w == Tuesday)))
56
0
                && m == December)
57
            // Matariki, it happens on Friday in June or July
58
            // official calendar released by the NZ government for the
59
            // next 30 years
60
0
            || (d == 20 && m == June && y == 2025)
61
0
            || (d == 21 && m == June && (y == 2030 || y == 2052))
62
0
            || (d == 24 && m == June && (y == 2022 || y == 2033 || y == 2044))
63
0
            || (d == 25 && m == June && (y == 2027 || y == 2038 || y == 2049))
64
0
            || (d == 28 && m == June && y == 2024)
65
0
            || (d == 29 && m == June && (y == 2035 || y == 2046))
66
0
            || (d == 30 && m == June && y == 2051)
67
0
            || (d == 2  && m == July && y == 2032)
68
0
            || (d == 3  && m == July && (y == 2043 || y == 2048))
69
0
            || (d == 6  && m == July && (y == 2029 || y == 2040))
70
0
            || (d == 7  && m == July && (y == 2034 || y == 2045))
71
0
            || (d == 10 && m == July && (y == 2026 || y == 2037))
72
0
            || (d == 11 && m == July && (y == 2031 || y == 2042))
73
0
            || (d == 14 && m == July && (y == 2023 || y == 2028))
74
0
            || (d == 15 && m == July && (y == 2039 || y == 2050))
75
0
            || (d == 18 && m == July && y == 2036)
76
0
            || (d == 19 && m == July && (y == 2041 || y == 2047))
77
            // Queen Elizabeth's funeral
78
0
            || (d == 26 && m == September && y == 2022))
79
0
            return false; // NOLINT(readability-simplify-boolean-expr)
80
0
        return true;
81
0
    }
82
83
0
    bool NewZealand::WellingtonImpl::isBusinessDay(const Date& date) const {
84
0
        if (!NewZealand::CommonImpl::isBusinessDay(date))
85
0
            return false;
86
0
        Weekday w = date.weekday();
87
0
        Day d = date.dayOfMonth();
88
0
        Month m = date.month();
89
        // Anniversary Day, Monday nearest January 22nd
90
0
        if ((d >= 19 && d <= 25) && w == Monday && m == January)
91
0
            return false; // NOLINT(readability-simplify-boolean-expr)
92
0
        return true;
93
0
    }
94
95
0
    bool NewZealand::AucklandImpl::isBusinessDay(const Date& date) const {
96
0
        if (!NewZealand::CommonImpl::isBusinessDay(date))
97
0
            return false;
98
0
        Weekday w = date.weekday();
99
0
        Day d = date.dayOfMonth();
100
0
        Month m = date.month();
101
        // Anniversary Day, Monday nearest January 29nd
102
0
        if ((d >= 26 && w == Monday && m == January)
103
0
            || (d == 1 && w == Monday && m == February))
104
0
            return false; // NOLINT(readability-simplify-boolean-expr)
105
0
        return true;
106
0
    }
107
        
108
109
0
    NewZealand::NewZealand(Market market) {
110
        // all calendar instances for a given market share the same implementation instance
111
0
        static auto wellingtonImpl = ext::make_shared<NewZealand::WellingtonImpl>();
112
0
        static auto aucklandImpl = ext::make_shared<NewZealand::AucklandImpl>();
113
114
0
        switch (market) {
115
0
          case Wellington:
116
0
            impl_ = wellingtonImpl;
117
0
            break;
118
0
          case Auckland:
119
0
            impl_ = aucklandImpl;
120
0
            break;
121
0
          default:
122
0
            QL_FAIL("unknown market");
123
0
        }
124
0
    }
125
126
}