diff options
Diffstat (limited to 'vendor/chrono/src/oldtime.rs')
-rw-r--r-- | vendor/chrono/src/oldtime.rs | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/vendor/chrono/src/oldtime.rs b/vendor/chrono/src/oldtime.rs index 8e2b3d2c0..e27be7db6 100644 --- a/vendor/chrono/src/oldtime.rs +++ b/vendor/chrono/src/oldtime.rs @@ -74,6 +74,7 @@ impl Duration { /// Equivalent to `Duration::seconds(weeks * 7 * 24 * 60 * 60)` with overflow checks. /// Panics when the duration is out of bounds. #[inline] + #[must_use] pub fn weeks(weeks: i64) -> Duration { let secs = weeks.checked_mul(SECS_PER_WEEK).expect("Duration::weeks out of bounds"); Duration::seconds(secs) @@ -83,6 +84,7 @@ impl Duration { /// Equivalent to `Duration::seconds(days * 24 * 60 * 60)` with overflow checks. /// Panics when the duration is out of bounds. #[inline] + #[must_use] pub fn days(days: i64) -> Duration { let secs = days.checked_mul(SECS_PER_DAY).expect("Duration::days out of bounds"); Duration::seconds(secs) @@ -92,6 +94,7 @@ impl Duration { /// Equivalent to `Duration::seconds(hours * 60 * 60)` with overflow checks. /// Panics when the duration is out of bounds. #[inline] + #[must_use] pub fn hours(hours: i64) -> Duration { let secs = hours.checked_mul(SECS_PER_HOUR).expect("Duration::hours ouf of bounds"); Duration::seconds(secs) @@ -101,6 +104,7 @@ impl Duration { /// Equivalent to `Duration::seconds(minutes * 60)` with overflow checks. /// Panics when the duration is out of bounds. #[inline] + #[must_use] pub fn minutes(minutes: i64) -> Duration { let secs = minutes.checked_mul(SECS_PER_MINUTE).expect("Duration::minutes out of bounds"); Duration::seconds(secs) @@ -110,6 +114,7 @@ impl Duration { /// Panics when the duration is more than `i64::MAX` seconds /// or less than `i64::MIN` seconds. #[inline] + #[must_use] pub fn seconds(seconds: i64) -> Duration { let d = Duration { secs: seconds, nanos: 0 }; if d < MIN || d > MAX { @@ -211,6 +216,7 @@ impl Duration { } /// Add two durations, returning `None` if overflow occurred. + #[must_use] pub fn checked_add(&self, rhs: &Duration) -> Option<Duration> { let mut secs = try_opt!(self.secs.checked_add(rhs.secs)); let mut nanos = self.nanos + rhs.nanos; @@ -229,6 +235,7 @@ impl Duration { } /// Subtract two durations, returning `None` if overflow occurred. + #[must_use] pub fn checked_sub(&self, rhs: &Duration) -> Option<Duration> { let mut secs = try_opt!(self.secs.checked_sub(rhs.secs)); let mut nanos = self.nanos - rhs.nanos; @@ -455,31 +462,9 @@ impl Error for OutOfRangeError { } } -// Copied from libnum #[inline] const fn div_mod_floor_64(this: i64, other: i64) -> (i64, i64) { - (div_floor_64(this, other), mod_floor_64(this, other)) -} - -#[inline] -const fn div_floor_64(this: i64, other: i64) -> i64 { - match div_rem_64(this, other) { - (d, r) if (r > 0 && other < 0) || (r < 0 && other > 0) => d - 1, - (d, _) => d, - } -} - -#[inline] -const fn mod_floor_64(this: i64, other: i64) -> i64 { - match this % other { - r if (r > 0 && other < 0) || (r < 0 && other > 0) => r + other, - r => r, - } -} - -#[inline] -const fn div_rem_64(this: i64, other: i64) -> (i64, i64) { - (this / other, this % other) + (this.div_euclid(other), this.rem_euclid(other)) } #[cfg(feature = "arbitrary")] |