mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-28 21:42:01 +00:00
Move Date::years_since() implementation into NaiveDate
This commit is contained in:
parent
645fca0c55
commit
03165c8658
10
src/date.rs
10
src/date.rs
@ -288,15 +288,7 @@ impl<Tz: TimeZone> Date<Tz> {
|
||||
|
||||
/// Returns the number of whole years from the given `base` until `self`.
|
||||
pub fn years_since(&self, base: Self) -> Option<u32> {
|
||||
let mut years = self.year() - base.year();
|
||||
if (self.month(), self.day()) < (base.month(), base.day()) {
|
||||
years -= 1;
|
||||
}
|
||||
|
||||
match years >= 0 {
|
||||
true => Some(years as u32),
|
||||
false => None,
|
||||
}
|
||||
self.date.years_since(base.date)
|
||||
}
|
||||
|
||||
/// The minimum possible `Date`.
|
||||
|
@ -1054,6 +1054,19 @@ impl NaiveDate {
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the number of whole years from the given `base` until `self`.
|
||||
pub fn years_since(&self, base: Self) -> Option<u32> {
|
||||
let mut years = self.year() - base.year();
|
||||
if (self.month(), self.day()) < (base.month(), base.day()) {
|
||||
years -= 1;
|
||||
}
|
||||
|
||||
match years >= 0 {
|
||||
true => Some(years as u32),
|
||||
false => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Formats the date with the specified formatting items.
|
||||
/// Otherwise it is the same as the ordinary `format` method.
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user