Crates.io | yearfrac |
lib.rs | yearfrac |
version | 0.2.0 |
source | src |
created_at | 2022-04-22 10:24:44.54141 |
updated_at | 2023-05-07 12:06:43.032728 |
description | Year fruction calculator for Rust |
homepage | https://github.com/AnatolyBug/yearfrac |
repository | https://github.com/AnatolyBug/yearfrac |
max_upload_size | |
id | 572094 |
size | 19,029 |
It was tested to match Excel's YEARFRAC function and with time go beyond. We support all 5 Excel's methodologies: nasd360 act/act act360 act365 eur360
Put this in your Cargo.toml
:
[dependencies]
yearfrac = {version="*", features=['serde', 'openapi']}
use yearfrac::DayCountConvention;
use chrono::{NaiveDate, Datelike};
let start = NaiveDate::from_ymd(1978, 2, 28);
let end = NaiveDate::from_ymd(2020, 5, 17);
let yf = DayCountConvention::from_int(0).unwrap()
.yearfrac(start, end);
assert!((yf - 42.21388888889).abs() < 1e-9);
let yf = DayCountConvention::from_str("act/act").unwrap()
.yearfrac(start, end);
assert!((yf - 42.21424933147).abs() < 1e-9);
use yearfrac::is_leap_year;
assert_eq!(is_leap_year(start.year()) as i32, 0)
let yf = DayCountConvention::US30360.yearfrac_signed(end, start);
assert!((yf + 42.21388888889).abs() < 1e-9);