Skip to content

Commit

Permalink
Move Add and Sub impls to naive::time module
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 23, 2023
1 parent 3afa49b commit 655a1a4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
18 changes: 18 additions & 0 deletions src/naive/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,15 @@ impl AddAssign<Duration> for NaiveTime {
}
}

impl Add<FixedOffset> 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`.
Expand Down Expand Up @@ -1262,6 +1271,15 @@ impl SubAssign<Duration> for NaiveTime {
}
}

impl Sub<FixedOffset> 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.
Expand Down
20 changes: 1 addition & 19 deletions src/offset/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -199,24 +199,6 @@ where
(lhs + OldDuration::seconds(i64::from(rhs))).with_nanosecond(nanos).unwrap()
}

impl Add<FixedOffset> for NaiveTime {
type Output = NaiveTime;

#[inline]
fn add(self, rhs: FixedOffset) -> NaiveTime {
self.overflowing_add_offset(rhs).0
}
}

impl Sub<FixedOffset> for NaiveTime {
type Output = NaiveTime;

#[inline]
fn sub(self, rhs: FixedOffset) -> NaiveTime {
self.overflowing_sub_offset(rhs).0
}
}

impl Add<FixedOffset> for NaiveDateTime {
type Output = NaiveDateTime;

Expand Down

0 comments on commit 655a1a4

Please sign in to comment.