Skip to content

Commit 84f3a75

Browse files
committed
Remove two-way conversion in arithmetic
1 parent 79a4b62 commit 84f3a75

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

time/src/duration.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ use crate::internal_macros::{
1919
#[cfg(feature = "std")]
2020
#[allow(deprecated)]
2121
use crate::Instant;
22-
#[cfg(feature = "std")]
23-
use crate::OffsetDateTime;
2422

2523
/// By explicitly inserting this enum where padding is expected, the compiler is able to better
2624
/// perform niche value optimization.
@@ -1586,7 +1584,14 @@ impl Sub<Duration> for SystemTime {
15861584
type Output = Self;
15871585

15881586
fn sub(self, duration: Duration) -> Self::Output {
1589-
(OffsetDateTime::from(self) - duration).into()
1587+
if duration.is_zero() {
1588+
self
1589+
} else if duration.is_positive() {
1590+
self - duration.unsigned_abs()
1591+
} else {
1592+
debug_assert!(duration.is_negative());
1593+
self + duration.unsigned_abs()
1594+
}
15901595
}
15911596
}
15921597

0 commit comments

Comments
 (0)