diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 32dd025740..fcd8876f4c 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -1166,22 +1166,13 @@ impl AddAssign for DateTime { } } -fn add_with_leapsecond(lhs: &T, rhs: i32) -> T -where - T: Timelike + Add, -{ - // extract and temporarily remove the fractional part and later recover it - let nanos = lhs.nanosecond(); - let lhs = lhs.with_nanosecond(0).unwrap(); - (lhs + OldDuration::seconds(i64::from(rhs))).with_nanosecond(nanos).unwrap() -} - impl Add for DateTime { type Output = DateTime; #[inline] - fn add(self, rhs: FixedOffset) -> DateTime { - add_with_leapsecond(&self, rhs.local_minus_utc()) + fn add(mut self, rhs: FixedOffset) -> DateTime { + self.datetime = self.naive_utc().checked_add_offset(rhs).unwrap(); + self } } @@ -1236,8 +1227,9 @@ impl Sub for DateTime { type Output = DateTime; #[inline] - fn sub(self, rhs: FixedOffset) -> DateTime { - add_with_leapsecond(&self, -rhs.local_minus_utc()) + fn sub(mut self, rhs: FixedOffset) -> DateTime { + self.datetime = self.naive_utc().checked_sub_offset(rhs).unwrap(); + self } }