pub fn checked_sub(self, rhs: Duration) -> Option<NaiveDateTime> {
        // Duration does not directly give its parts, so we need some additional calculations.
        let days = rhs.num_days();
        let nanos = (rhs - Duration::days(days)).num_nanoseconds().unwrap();
        debug_assert!(Duration::days(days) + Duration::nanoseconds(nanos) == rhs);
        debug_assert!(-86400_000_000_000 < nanos && nanos < 86400_000_000_000);

        let mut date = try_opt!(self.date.checked_sub(Duration::days(days)));
        let time = self.time - Duration::nanoseconds(nanos);

        // time always wraps around, but date needs to be adjusted for overflow.
        if nanos > 0 && time > self.time {
            date = try_opt!(date.pred_opt());
        } else if nanos < 0 && time < self.time {
            date = try_opt!(date.succ_opt());
        }
        Some(NaiveDateTime { date: date, time: time })
    }
/// Subtracts given `Duration` from the current date and time.
///
/// Returns `None` when it will result in overflow.
Subtracts given `Duration` from the current date and time.
Returns `None` when it will result in overflow.
Subtracts given ` Duration ` from the current date and time . Returns ` None ` when it will result in overflow .
pub fn checked_sub(self, rhs: Duration) -> Option<NaiveDateTime> {
        // Duration does not directly give its parts, so we need some additional calculations.
        let days = rhs.num_days();
        let nanos = (rhs - Duration::days(days)).num_nanoseconds().unwrap();
        debug_assert!(Duration::days(days) + Duration::nanoseconds(nanos) == rhs);
        debug_assert!(-86400_000_000_000 < nanos && nanos < 86400_000_000_000);
        let mut date = try_opt!(self.date.checked_sub(Duration::days(days)));
        let time = self.time - Duration::nanoseconds(nanos);
        // time always wraps around, but date needs to be adjusted for overflow.
        if nanos > 0 && time > self.time {
            date = try_opt!(date.pred_opt());
        } else if nanos < 0 && time < self.time {
            date = try_opt!(date.succ_opt());
        }
        Some(NaiveDateTime { date: date, time: time })
    }
pub fn checked_sub ( self , rhs : Duration ) -> Option < NaiveDateTime > { // Duration does not directly give its parts, so we need some additional calculations. let days = rhs . num_days ( ) ; let nanos = ( rhs - Duration :: days ( days ) ) . num_nanoseconds ( ) . unwrap ( ) ; debug_assert ! ( Duration days ( days ) Duration nanoseconds ( nanos ) rhs ) ; debug_assert ! ( 86400_000_000_000 nanos nanos 86400_000_000_000 ) ; let mut date = try_opt ! ( self date checked_sub ( Duration days ( days ) ) ) ; let time = self . time - Duration :: nanoseconds ( nanos ) ; // time always wraps around, but date needs to be adjusted for overflow. if nanos > 0 && time > self . time { date = try_opt ! ( date pred_opt ( ) ) ; } else if nanos < 0 && time < self . time { date = try_opt ! ( date succ_opt ( ) ) ; } Some ( NaiveDateTime { date : date , time : time } ) }
Subtracts given `Duration` from the current date and time.
Subtracts given ` Duration ` from the current date and time .
self
rhs
Duration
self
rhs
Duration