1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! Day-counter base: measuring a period as day counts and year fractions.
//!
//! Port of `ql/time/daycounter.{hpp,cpp}`. QuantLib uses the Bridge pattern: a
//! `DayCounter` value holds a `shared_ptr<Impl>`, and each convention subclasses
//! `Impl` to answer [`DayCounterImpl::day_count`] and
//! [`DayCounterImpl::year_fraction`]. Here the same split is expressed with a
//! [`DayCounterImpl`] trait object behind a [`Shared`]: [`DayCounter`] holds the
//! shared implementation and forwards to it. The concrete conventions live in
//! [`daycounters`](crate::time::daycounters).
//!
//! ## Divergences from QuantLib
//!
//! QuantLib's default-constructed `DayCounter` is *empty* (a null `impl_`), and
//! its accessors `QL_REQUIRE` a non-null implementation. This port omits the
//! empty state: a [`DayCounter`] always wraps a concrete implementation, so the
//! wrapper's accessors never trip the null-implementation check QuantLib guards
//! against. (This does not make every call infallible: individual conventions
//! may still panic on their own preconditions - for example the Canadian and
//! ISMA counters require a valid reference period - as documented in their
//! `# Panics` sections.) The empty placeholder is only used by higher layers
//! (schedules, coupons) as a "not yet set" marker; it will be reintroduced as an
//! `Option<DayCounter>` at those call sites when they are ported, keeping the
//! counter type itself always-valid.
use fmt;
use crateShared;
use crate;
use crateTime;
/// The convention-specific behaviour behind a [`DayCounter`].
///
/// Mirrors QuantLib's `DayCounter::Impl`: [`day_count`](Self::day_count) has a
/// default (the raw serial-number difference `d2 - d1`) that simple counters
/// inherit, while [`year_fraction`](Self::year_fraction) is always convention
/// specific. The four-date `year_fraction` signature keeps QuantLib's reference
/// period, which only the schedule-aware conventions (Actual/Actual ISMA,
/// Actual/365 Canadian) consult.
/// A day-counting convention: the length of a period as a day count and as a
/// fraction of a year.
///
/// Cloning is cheap and shares the underlying implementation. Concrete
/// conventions in [`daycounters`](crate::time::daycounters) build one via
/// [`from_impl`](Self::from_impl).