Skip to content

Commit

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

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

#[inline]
fn add(self, rhs: FixedOffset) -> NaiveDateTime {
self.checked_add_offset(rhs).unwrap()
}
}

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

Expand Down Expand Up @@ -1746,6 +1755,15 @@ impl SubAssign<Duration> for NaiveDateTime {
}
}

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

#[inline]
fn sub(self, rhs: FixedOffset) -> NaiveDateTime {
self.checked_sub_offset(rhs).unwrap()
}
}

/// A subtraction of Months from `NaiveDateTime` clamped to valid days in resulting month.
///
/// # Panics
Expand Down
18 changes: 0 additions & 18 deletions src/offset/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,6 @@ where
(lhs + OldDuration::seconds(i64::from(rhs))).with_nanosecond(nanos).unwrap()
}

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

#[inline]
fn add(self, rhs: FixedOffset) -> NaiveDateTime {
self.checked_add_offset(rhs).unwrap()
}
}

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

#[inline]
fn sub(self, rhs: FixedOffset) -> NaiveDateTime {
self.checked_sub_offset(rhs).unwrap()
}
}

impl<Tz: TimeZone> Add<FixedOffset> for DateTime<Tz> {
type Output = DateTime<Tz>;

Expand Down

0 comments on commit c836a1f

Please sign in to comment.