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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
// Copyright 2026 Regit.io — Nicolas Koenig
// SPDX-License-Identifier: Apache-2.0
//! NL/365 — "No-Leap / 365", conventional money-market variant.
//!
//! NL/365 is a money-market variant of Act/365F that excludes 29 February
//! from the numerator: the fraction's numerator is the actual count of
//! calendar days between `start` and `end`, *minus* the number of
//! 29-February dates that fall in the half-open interval `[start, end)`;
//! the denominator is the fixed constant 365. The effect is that a full
//! leap-year span and a full non-leap-year span both return exactly
//! `1.0` — the convention is "leap-year-blind" by construction in the
//! same way Act/360 is leap-year-blind by virtue of a constant 360
//! denominator, but here every year — leap or not — contributes exactly
//! `365 / 365` to the fraction.
//!
//! The convention has no entry in the ISDA 2006 Definitions §4.16
//! catalogue; it is a market practice convention found principally in
//! some legacy money-market and fixed-income contracts, and is included
//! here for completeness alongside the ICMA Act/365L and the ISDA
//! fractions.
//!
//! # Algorithm
//!
//! ```text
//! numerator = days_between(start, end) - leap_days_in_interval(start, end)
//! denominator = 365
//! fraction = numerator / 365.0
//! ```
//!
//! Where `days_between` is the signed count of days from `start` to
//! `end`, end-exclusive, start-inclusive, and `leap_days_in_interval`
//! is the count of dates `Date::ymd(y, 2, 29)` (for any leap year `y`)
//! satisfying `start <= d < end` — the same half-open convention.
//!
//! For an inverted interval (`start > end`) the function preserves
//! `fraction(end, start) == -fraction(start, end)`: the leap-day count
//! is taken over the forward half-open interval and the sign is carried
//! by the signed `days_between`.
//!
//! # Worked example — Q1 2024 straddles 29 February
//!
//! ```text
//! start = 2024-01-01
//! end = 2024-04-01
//! days = 31 + 29 + 31 = 91 (Jan + Feb (2024 leap) + Mar)
//! 29-Feb in [start, end): 2024-02-29 → subtract 1
//! num = 91 - 1 = 90
//! f = 90 / 365 = 0.246575342465753
//! ```
//!
//! # References
//!
//! - Market-convention day-count catalogues that list NL/365 alongside
//! the ISDA / ICMA fractions — the convention is non-statutory; no
//! single primary reference applies.
use crateDate;
/// Computes the NL/365 year fraction between two dates.
///
/// The result is `(days_between(start, end) - leap_days_in_interval) /
/// 365`, where `days_between` is signed and `leap_days_in_interval` is
/// the count of 29-February dates in the half-open interval
/// `[min(start, end), max(start, end))`. See the module-level docstring
/// for the full algorithm and worked example.
///
/// The function is sign-preserving: `fraction(end, start) ==
/// -fraction(start, end)`. The crate does not reject inverted intervals
/// because some callers compute reverse-period accruals.
///
/// # Examples
///
/// ```
/// use regit_daycount::Date;
/// use regit_daycount::day_count::nl_365;
///
/// // Q1 2024 straddles 2024-02-29: 91 actual days − 1 leap day = 90.
/// let start = Date::ymd(2024, 1, 1).unwrap();
/// let end = Date::ymd(2024, 4, 1).unwrap();
/// assert!((nl_365::fraction(start, end) - 90.0_f64 / 365.0).abs() < 1e-12);
/// ```
/// Counts the 29-February dates that fall in the half-open interval
/// `[lo, hi)`, where `lo <= hi`.
///
/// Iterates over each year touched by the interval (inclusive of both
/// endpoints' years) and tests whether `Date::ymd(y, 2, 29)` — when it
/// exists, i.e. when `y` is a Gregorian leap year — lies in `[lo, hi)`.
/// The iteration is bounded by the year span of the interval and is
/// allocation-free.
//
// `lo <= hi` is established by the caller (the only call site orders
// the endpoints before invoking this helper); the loop bound therefore
// terminates and never iterates an empty range backward.