From a47e0e3c1601616005f9b6b885430e518af18e7c Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Fri, 19 May 2023 14:38:30 +0200 Subject: [PATCH] Move `Add` and `Sub` impls to `naive::time` module --- src/naive/time/mod.rs | 18 ++++++++++++++++++ src/offset/fixed.rs | 20 +------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/naive/time/mod.rs b/src/naive/time/mod.rs index 53617b9f6e..b9de19d0cb 100644 --- a/src/naive/time/mod.rs +++ b/src/naive/time/mod.rs @@ -1180,6 +1180,15 @@ impl AddAssign for NaiveTime { } } +impl Add for NaiveTime { + type Output = NaiveTime; + + #[inline] + fn add(self, rhs: FixedOffset) -> NaiveTime { + self.overflowing_add_offset(rhs).0 + } +} + /// A subtraction of `Duration` from `NaiveTime` wraps around and never overflows or underflows. /// In particular the addition ignores integral number of days. /// It is the same as the addition with a negated `Duration`. @@ -1262,6 +1271,15 @@ impl SubAssign for NaiveTime { } } +impl Sub for NaiveTime { + type Output = NaiveTime; + + #[inline] + fn sub(self, rhs: FixedOffset) -> NaiveTime { + self.overflowing_sub_offset(rhs).0 + } +} + /// Subtracts another `NaiveTime` from the current time. /// Returns a `Duration` within +/- 1 day. /// This does not overflow or underflow at all. diff --git a/src/offset/fixed.rs b/src/offset/fixed.rs index 57ceccbe6c..8038e1a5e5 100644 --- a/src/offset/fixed.rs +++ b/src/offset/fixed.rs @@ -13,7 +13,7 @@ use rkyv::{Archive, Deserialize, Serialize}; use super::{LocalResult, Offset, TimeZone}; use crate::duration::Duration as OldDuration; use crate::format::{scan, OUT_OF_RANGE}; -use crate::naive::{NaiveDate, NaiveDateTime, NaiveTime}; +use crate::naive::{NaiveDate, NaiveDateTime}; use crate::{DateTime, ParseError, Timelike}; /// The time zone with fixed offset, from UTC-23:59:59 to UTC+23:59:59. @@ -199,24 +199,6 @@ where (lhs + OldDuration::seconds(i64::from(rhs))).with_nanosecond(nanos).unwrap() } -impl Add for NaiveTime { - type Output = NaiveTime; - - #[inline] - fn add(self, rhs: FixedOffset) -> NaiveTime { - self.overflowing_add_offset(rhs).0 - } -} - -impl Sub for NaiveTime { - type Output = NaiveTime; - - #[inline] - fn sub(self, rhs: FixedOffset) -> NaiveTime { - self.overflowing_sub_offset(rhs).0 - } -} - impl Add for NaiveDateTime { type Output = NaiveDateTime;