Fix YEARFRAC basis 0 for February-end start and 31st end

Found while testing crates/functions/src/date.rs:443-457 (yearfrac_core, basis 0)

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-24 17:10:13 +02:00
co-authored by Claude Haiku 5.5
parent 3099df934e
commit b4487663aa
+12 -9
View File
@@ -441,18 +441,14 @@ pub(crate) fn yearfrac_core(sys: DateSystem, s: i64, e: i64, basis: i64) -> R<f6
Ok(match basis {
0 => {
let (mut a, mut b) = (d1.day as i64, d2.day as i64);
if a == 31 && b == 31 {
a = 30;
if last_of_feb(&d1) && last_of_feb(&d2) {
b = 30;
} else if a == 31 {
}
if last_of_feb(&d1) || a == 31 {
a = 30;
} else if a == 30 && b == 31 {
}
if a == 30 && b == 31 {
b = 30;
} else if last_of_feb(&d1) && last_of_feb(&d2) {
a = 30;
b = 30;
} else if last_of_feb(&d1) {
a = 30;
}
((d2.year as i64 - d1.year as i64) * 360 + (d2.month as i64 - d1.month as i64) * 30 + b - a) as f64 / 360.0
}
@@ -811,6 +807,13 @@ mod tests {
close(ev("YEARFRAC", vec![s, n(d(2012.0, 1.0, 1.0))]), 0.0);
}
#[test]
fn yearfrac_basis0_feb_end_to_31() {
close(ev("YEARFRAC", vec![n(d(2021.0, 2.0, 28.0)), n(d(2021.0, 3.0, 31.0)), n(0.0)]), 30.0 / 360.0);
close(ev("YEARFRAC", vec![n(d(2020.0, 2.0, 29.0)), n(d(2020.0, 3.0, 31.0)), n(0.0)]), 30.0 / 360.0);
close(ev("YEARFRAC", vec![n(d(2021.0, 2.0, 28.0)), n(d(2021.0, 2.0, 28.0)), n(0.0)]), 0.0);
}
#[test]
fn date_lifting() {
let v = ev("YEAR", vec![av(row(&[43831.0, 46302.0]))]);