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
//! # findates — Financial date arithmetic for Rust
//!
//! Any meaningful financial calculation requires a precise notion of time.
//! While there is extensive literature on pricing models and financial theory,
//! much less attention is given to the practical task of constructing the time
//! inputs those models depend on.
//!
//! `findates` focuses on this layer: generating correct schedules, applying
//! conventions, and computing date fractions consistently.
//!
//! ## Modules
//!
//! - [`calendar`] — [`Calendar`](calendar::Calendar) struct: weekends and holiday sets, set operations
//! - [`conventions`] — [`DayCount`](conventions::DayCount), [`AdjustRule`](conventions::AdjustRule), [`Frequency`](conventions::Frequency) enums
//! - [`algebra`] — core functions: business day checks, adjustment, day count fractions, schedule counting
//! - [`schedule`] — [`Schedule`](schedule::Schedule) and lazy [`ScheduleIterator`](schedule::ScheduleIterator)
//! - [`error`] — [`DayCountError`] returned by fallible functions
//!
//! ## Features
//!
//! - **`serde`** *(optional)* — derives `Serialize` and `Deserialize` for
//! [`DayCount`](conventions::DayCount), [`AdjustRule`](conventions::AdjustRule),
//! [`Frequency`](conventions::Frequency), and [`Calendar`](calendar::Calendar).
//! Enable in `Cargo.toml`:
//! ```toml
//! [dependencies]
//! findates = { version = "0.1", features = ["serde"] }
//! ```
//!
//! ## Date Types
//!
//! findates uses [`chrono::NaiveDate`] as its date representation throughout.
//! All public functions accept and return `NaiveDate` (aliased as
//! [`FinDate`] for convenience). Timezone-aware dates are not supported —
//! financial date arithmetic operates on calendar dates without reference
//! to time of day or timezone.
//!
//! If your codebase uses the [`time`](https://docs.rs/time) crate, you will
//! need to convert to `NaiveDate` at the boundary. Broader date type
//! interoperability is planned for a future release.
//!
//! ## Quick start
//!
//! ```rust
//! use chrono::NaiveDate;
//! use findates::calendar::basic_calendar;
//! use findates::conventions::{AdjustRule, DayCount, Frequency};
//! use findates::schedule::Schedule;
//! use findates::algebra;
//!
//! // Build a calendar with standard Sat/Sun weekend
//! let cal = basic_calendar();
//!
//! // Adjust a Saturday to the next business day (Monday)
//! let saturday = NaiveDate::from_ymd_opt(2024, 3, 16).unwrap();
//! let adj = algebra::adjust(&saturday, Some(&cal), Some(AdjustRule::Following));
//! assert_eq!(adj, NaiveDate::from_ymd_opt(2024, 3, 18).unwrap());
//!
//! // Generate a semi-annual schedule (2023 is not a leap year: exactly 365 days)
//! let anchor = NaiveDate::from_ymd_opt(2023, 1, 1).unwrap();
//! let end = NaiveDate::from_ymd_opt(2024, 1, 1).unwrap();
//! let sched = Schedule::new(Frequency::Semiannual, None, None);
//! let dates = sched.generate(&anchor, &end).unwrap();
//! assert_eq!(dates.len(), 3); // 2023-01-01, 2023-07-01, 2024-01-01
//!
//! // Act/365 over 365 days = exactly 1.0
//! let dcf = algebra::day_count_fraction(
//! &anchor, &end, DayCount::Act365, None, None,
//! ).unwrap();
//! assert!((dcf - 1.0).abs() < 1e-9);
//! ```
pub
pub use DayCountError;
/// Type alias for the date type used throughout the library.
pub type FinDate = NaiveDate;