Skip to content

Commit db12973

Browse files
authored
Added doctest for the NaiveDate years_since function (#1755)
1 parent 34b5f49 commit db12973

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/naive/date/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,17 @@ impl NaiveDate {
11841184
/// # Errors
11851185
///
11861186
/// Returns `None` if `base > self`.
1187+
///
1188+
/// # Example
1189+
///
1190+
/// ```
1191+
/// # use chrono::{NaiveDate};
1192+
/// #
1193+
/// let base: NaiveDate = "2025-01-01".parse().unwrap();
1194+
/// let date: NaiveDate = "2030-01-01".parse().unwrap();
1195+
///
1196+
/// assert_eq!(date.years_since(base), Some(5))
1197+
/// ```
11871198
#[must_use]
11881199
pub const fn years_since(&self, base: Self) -> Option<u32> {
11891200
let mut years = self.year() - base.year();

0 commit comments

Comments
 (0)