Skip to content

Commit

Permalink
Tests: replace TimeDelta::days with try_days
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Mar 6, 2024
1 parent e8f9b5e commit 9f23c08
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 122 deletions.
8 changes: 4 additions & 4 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,8 +1500,8 @@ fn test_datetime_add_assign_local() {

// ensure we cross a DST transition
for i in 1..=365 {
datetime_add += TimeDelta::days(1);
assert_eq!(datetime_add, datetime + TimeDelta::days(i))
datetime_add += TimeDelta::try_days(1).unwrap();
assert_eq!(datetime_add, datetime + TimeDelta::try_days(i).unwrap())
}
}

Expand Down Expand Up @@ -1709,8 +1709,8 @@ fn test_datetime_sub_assign_local() {

// ensure we cross a DST transition
for i in 1..=365 {
datetime_sub -= TimeDelta::days(1);
assert_eq!(datetime_sub, datetime - TimeDelta::days(i))
datetime_sub -= TimeDelta::try_days(1).unwrap();
assert_eq!(datetime_sub, datetime - TimeDelta::try_days(i).unwrap())
}
}

Expand Down
97 changes: 65 additions & 32 deletions src/naive/date/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,16 +1057,16 @@ impl NaiveDate {
///
/// let d = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap();
/// assert_eq!(
/// d.checked_add_signed(TimeDelta::days(40)),
/// d.checked_add_signed(TimeDelta::try_days(40).unwrap()),
/// Some(NaiveDate::from_ymd_opt(2015, 10, 15).unwrap())
/// );
/// assert_eq!(
/// d.checked_add_signed(TimeDelta::days(-40)),
/// d.checked_add_signed(TimeDelta::try_days(-40).unwrap()),
/// Some(NaiveDate::from_ymd_opt(2015, 7, 27).unwrap())
/// );
/// assert_eq!(d.checked_add_signed(TimeDelta::days(1_000_000_000)), None);
/// assert_eq!(d.checked_add_signed(TimeDelta::days(-1_000_000_000)), None);
/// assert_eq!(NaiveDate::MAX.checked_add_signed(TimeDelta::days(1)), None);
/// assert_eq!(d.checked_add_signed(TimeDelta::try_days(1_000_000_000).unwrap()), None);
/// assert_eq!(d.checked_add_signed(TimeDelta::try_days(-1_000_000_000).unwrap()), None);
/// assert_eq!(NaiveDate::MAX.checked_add_signed(TimeDelta::try_days(1).unwrap()), None);
/// ```
#[must_use]
pub const fn checked_add_signed(self, rhs: TimeDelta) -> Option<NaiveDate> {
Expand All @@ -1090,16 +1090,16 @@ impl NaiveDate {
///
/// let d = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap();
/// assert_eq!(
/// d.checked_sub_signed(TimeDelta::days(40)),
/// d.checked_sub_signed(TimeDelta::try_days(40).unwrap()),
/// Some(NaiveDate::from_ymd_opt(2015, 7, 27).unwrap())
/// );
/// assert_eq!(
/// d.checked_sub_signed(TimeDelta::days(-40)),
/// d.checked_sub_signed(TimeDelta::try_days(-40).unwrap()),
/// Some(NaiveDate::from_ymd_opt(2015, 10, 15).unwrap())
/// );
/// assert_eq!(d.checked_sub_signed(TimeDelta::days(1_000_000_000)), None);
/// assert_eq!(d.checked_sub_signed(TimeDelta::days(-1_000_000_000)), None);
/// assert_eq!(NaiveDate::MIN.checked_sub_signed(TimeDelta::days(1)), None);
/// assert_eq!(d.checked_sub_signed(TimeDelta::try_days(1_000_000_000).unwrap()), None);
/// assert_eq!(d.checked_sub_signed(TimeDelta::try_days(-1_000_000_000).unwrap()), None);
/// assert_eq!(NaiveDate::MIN.checked_sub_signed(TimeDelta::try_days(1).unwrap()), None);
/// ```
#[must_use]
pub const fn checked_sub_signed(self, rhs: TimeDelta) -> Option<NaiveDate> {
Expand All @@ -1125,12 +1125,27 @@ impl NaiveDate {
/// let since = NaiveDate::signed_duration_since;
///
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2014, 1, 1)), TimeDelta::zero());
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2013, 12, 31)), TimeDelta::days(1));
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2014, 1, 2)), TimeDelta::days(-1));
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2013, 9, 23)), TimeDelta::days(100));
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2013, 1, 1)), TimeDelta::days(365));
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2010, 1, 1)), TimeDelta::days(365 * 4 + 1));
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(1614, 1, 1)), TimeDelta::days(365 * 400 + 97));
/// assert_eq!(
/// since(from_ymd(2014, 1, 1), from_ymd(2013, 12, 31)),
/// TimeDelta::try_days(1).unwrap()
/// );
/// assert_eq!(since(from_ymd(2014, 1, 1), from_ymd(2014, 1, 2)), TimeDelta::try_days(-1).unwrap());
/// assert_eq!(
/// since(from_ymd(2014, 1, 1), from_ymd(2013, 9, 23)),
/// TimeDelta::try_days(100).unwrap()
/// );
/// assert_eq!(
/// since(from_ymd(2014, 1, 1), from_ymd(2013, 1, 1)),
/// TimeDelta::try_days(365).unwrap()
/// );
/// assert_eq!(
/// since(from_ymd(2014, 1, 1), from_ymd(2010, 1, 1)),
/// TimeDelta::try_days(365 * 4 + 1).unwrap()
/// );
/// assert_eq!(
/// since(from_ymd(2014, 1, 1), from_ymd(1614, 1, 1)),
/// TimeDelta::try_days(365 * 400 + 97).unwrap()
/// );
/// ```
#[must_use]
pub const fn signed_duration_since(self, rhs: NaiveDate) -> TimeDelta {
Expand Down Expand Up @@ -1894,11 +1909,17 @@ impl Datelike for NaiveDate {
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::zero(), from_ymd(2014, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::seconds(86399), from_ymd(2014, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::seconds(-86399), from_ymd(2014, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::days(1), from_ymd(2014, 1, 2));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::days(-1), from_ymd(2013, 12, 31));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::days(364), from_ymd(2014, 12, 31));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::days(365 * 4 + 1), from_ymd(2018, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::days(365 * 400 + 97), from_ymd(2414, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::try_days(1).unwrap(), from_ymd(2014, 1, 2));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::try_days(-1).unwrap(), from_ymd(2013, 12, 31));
/// assert_eq!(from_ymd(2014, 1, 1) + TimeDelta::try_days(364).unwrap(), from_ymd(2014, 12, 31));
/// assert_eq!(
/// from_ymd(2014, 1, 1) + TimeDelta::try_days(365 * 4 + 1).unwrap(),
/// from_ymd(2018, 1, 1)
/// );
/// assert_eq!(
/// from_ymd(2014, 1, 1) + TimeDelta::try_days(365 * 400 + 97).unwrap(),
/// from_ymd(2414, 1, 1)
/// );
/// ```
///
/// [`NaiveDate::checked_add_signed`]: crate::NaiveDate::checked_add_signed
Expand Down Expand Up @@ -2037,11 +2058,17 @@ impl Sub<Days> for NaiveDate {
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::zero(), from_ymd(2014, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::seconds(86399), from_ymd(2014, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::seconds(-86399), from_ymd(2014, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(1), from_ymd(2013, 12, 31));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(-1), from_ymd(2014, 1, 2));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(364), from_ymd(2013, 1, 2));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(365 * 4 + 1), from_ymd(2010, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::days(365 * 400 + 97), from_ymd(1614, 1, 1));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::try_days(1).unwrap(), from_ymd(2013, 12, 31));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::try_days(-1).unwrap(), from_ymd(2014, 1, 2));
/// assert_eq!(from_ymd(2014, 1, 1) - TimeDelta::try_days(364).unwrap(), from_ymd(2013, 1, 2));
/// assert_eq!(
/// from_ymd(2014, 1, 1) - TimeDelta::try_days(365 * 4 + 1).unwrap(),
/// from_ymd(2010, 1, 1)
/// );
/// assert_eq!(
/// from_ymd(2014, 1, 1) - TimeDelta::try_days(365 * 400 + 97).unwrap(),
/// from_ymd(1614, 1, 1)
/// );
/// ```
///
/// [`NaiveDate::checked_sub_signed`]: crate::NaiveDate::checked_sub_signed
Expand Down Expand Up @@ -2088,12 +2115,18 @@ impl SubAssign<TimeDelta> for NaiveDate {
/// let from_ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
///
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2014, 1, 1), TimeDelta::zero());
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 12, 31), TimeDelta::days(1));
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2014, 1, 2), TimeDelta::days(-1));
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 9, 23), TimeDelta::days(100));
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 1, 1), TimeDelta::days(365));
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2010, 1, 1), TimeDelta::days(365 * 4 + 1));
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(1614, 1, 1), TimeDelta::days(365 * 400 + 97));
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 12, 31), TimeDelta::try_days(1).unwrap());
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2014, 1, 2), TimeDelta::try_days(-1).unwrap());
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 9, 23), TimeDelta::try_days(100).unwrap());
/// assert_eq!(from_ymd(2014, 1, 1) - from_ymd(2013, 1, 1), TimeDelta::try_days(365).unwrap());
/// assert_eq!(
/// from_ymd(2014, 1, 1) - from_ymd(2010, 1, 1),
/// TimeDelta::try_days(365 * 4 + 1).unwrap()
/// );
/// assert_eq!(
/// from_ymd(2014, 1, 1) - from_ymd(1614, 1, 1),
/// TimeDelta::try_days(365 * 400 + 97).unwrap()
/// );
/// ```
impl Sub<NaiveDate> for NaiveDate {
type Output = TimeDelta;
Expand Down
50 changes: 29 additions & 21 deletions src/naive/date/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,20 +457,28 @@ fn test_date_add() {
check((2014, 1, 1), TimeDelta::seconds(86399), Some((2014, 1, 1)));
// always round towards zero
check((2014, 1, 1), TimeDelta::seconds(-86399), Some((2014, 1, 1)));
check((2014, 1, 1), TimeDelta::days(1), Some((2014, 1, 2)));
check((2014, 1, 1), TimeDelta::days(-1), Some((2013, 12, 31)));
check((2014, 1, 1), TimeDelta::days(364), Some((2014, 12, 31)));
check((2014, 1, 1), TimeDelta::days(365 * 4 + 1), Some((2018, 1, 1)));
check((2014, 1, 1), TimeDelta::days(365 * 400 + 97), Some((2414, 1, 1)));
check((2014, 1, 1), TimeDelta::try_days(1).unwrap(), Some((2014, 1, 2)));
check((2014, 1, 1), TimeDelta::try_days(-1).unwrap(), Some((2013, 12, 31)));
check((2014, 1, 1), TimeDelta::try_days(364).unwrap(), Some((2014, 12, 31)));
check((2014, 1, 1), TimeDelta::try_days(365 * 4 + 1).unwrap(), Some((2018, 1, 1)));
check((2014, 1, 1), TimeDelta::try_days(365 * 400 + 97).unwrap(), Some((2414, 1, 1)));

check((-7, 1, 1), TimeDelta::days(365 * 12 + 3), Some((5, 1, 1)));
check((-7, 1, 1), TimeDelta::try_days(365 * 12 + 3).unwrap(), Some((5, 1, 1)));

// overflow check
check((0, 1, 1), TimeDelta::days(MAX_DAYS_FROM_YEAR_0 as i64), Some((MAX_YEAR, 12, 31)));
check((0, 1, 1), TimeDelta::days(MAX_DAYS_FROM_YEAR_0 as i64 + 1), None);
check(
(0, 1, 1),
TimeDelta::try_days(MAX_DAYS_FROM_YEAR_0 as i64).unwrap(),
Some((MAX_YEAR, 12, 31)),
);
check((0, 1, 1), TimeDelta::try_days(MAX_DAYS_FROM_YEAR_0 as i64 + 1).unwrap(), None);
check((0, 1, 1), TimeDelta::max_value(), None);
check((0, 1, 1), TimeDelta::days(MIN_DAYS_FROM_YEAR_0 as i64), Some((MIN_YEAR, 1, 1)));
check((0, 1, 1), TimeDelta::days(MIN_DAYS_FROM_YEAR_0 as i64 - 1), None);
check(
(0, 1, 1),
TimeDelta::try_days(MIN_DAYS_FROM_YEAR_0 as i64).unwrap(),
Some((MIN_YEAR, 1, 1)),
);
check((0, 1, 1), TimeDelta::try_days(MIN_DAYS_FROM_YEAR_0 as i64 - 1).unwrap(), None);
check((0, 1, 1), TimeDelta::min_value(), None);
}

Expand All @@ -484,14 +492,14 @@ fn test_date_sub() {
}

check((2014, 1, 1), (2014, 1, 1), TimeDelta::zero());
check((2014, 1, 2), (2014, 1, 1), TimeDelta::days(1));
check((2014, 12, 31), (2014, 1, 1), TimeDelta::days(364));
check((2015, 1, 3), (2014, 1, 1), TimeDelta::days(365 + 2));
check((2018, 1, 1), (2014, 1, 1), TimeDelta::days(365 * 4 + 1));
check((2414, 1, 1), (2014, 1, 1), TimeDelta::days(365 * 400 + 97));
check((2014, 1, 2), (2014, 1, 1), TimeDelta::try_days(1).unwrap());
check((2014, 12, 31), (2014, 1, 1), TimeDelta::try_days(364).unwrap());
check((2015, 1, 3), (2014, 1, 1), TimeDelta::try_days(365 + 2).unwrap());
check((2018, 1, 1), (2014, 1, 1), TimeDelta::try_days(365 * 4 + 1).unwrap());
check((2414, 1, 1), (2014, 1, 1), TimeDelta::try_days(365 * 400 + 97).unwrap());

check((MAX_YEAR, 12, 31), (0, 1, 1), TimeDelta::days(MAX_DAYS_FROM_YEAR_0 as i64));
check((MIN_YEAR, 1, 1), (0, 1, 1), TimeDelta::days(MIN_DAYS_FROM_YEAR_0 as i64));
check((MAX_YEAR, 12, 31), (0, 1, 1), TimeDelta::try_days(MAX_DAYS_FROM_YEAR_0 as i64).unwrap());
check((MIN_YEAR, 1, 1), (0, 1, 1), TimeDelta::try_days(MIN_DAYS_FROM_YEAR_0 as i64).unwrap());
}

#[test]
Expand Down Expand Up @@ -539,19 +547,19 @@ fn test_date_sub_days() {
fn test_date_addassignment() {
let ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
let mut date = ymd(2016, 10, 1);
date += TimeDelta::days(10);
date += TimeDelta::try_days(10).unwrap();
assert_eq!(date, ymd(2016, 10, 11));
date += TimeDelta::days(30);
date += TimeDelta::try_days(30).unwrap();
assert_eq!(date, ymd(2016, 11, 10));
}

#[test]
fn test_date_subassignment() {
let ymd = |y, m, d| NaiveDate::from_ymd_opt(y, m, d).unwrap();
let mut date = ymd(2016, 10, 11);
date -= TimeDelta::days(10);
date -= TimeDelta::try_days(10).unwrap();
assert_eq!(date, ymd(2016, 10, 1));
date -= TimeDelta::days(2);
date -= TimeDelta::try_days(2).unwrap();
assert_eq!(date, ymd(2016, 9, 29));
}

Expand Down
16 changes: 8 additions & 8 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl NaiveDateTime {
/// ```
/// # use chrono::{TimeDelta, NaiveDate};
/// # let hms = |h, m, s| NaiveDate::from_ymd_opt(2016, 7, 8).unwrap().and_hms_opt(h, m, s).unwrap();
/// assert_eq!(hms(3, 5, 7).checked_add_signed(TimeDelta::days(1_000_000_000)), None);
/// assert_eq!(hms(3, 5, 7).checked_add_signed(TimeDelta::try_days(1_000_000_000).unwrap()), None);
/// ```
///
/// Leap seconds are handled,
Expand All @@ -514,7 +514,7 @@ impl NaiveDateTime {
/// Some(hmsm(3, 6, 9, 300)));
/// assert_eq!(leap.checked_add_signed(TimeDelta::seconds(-10)),
/// Some(hmsm(3, 5, 50, 300)));
/// assert_eq!(leap.checked_add_signed(TimeDelta::days(1)),
/// assert_eq!(leap.checked_add_signed(TimeDelta::try_days(1).unwrap()),
/// Some(from_ymd(2016, 7, 9).and_hms_milli_opt(3, 5, 59, 300).unwrap()));
/// ```
#[must_use]
Expand Down Expand Up @@ -666,7 +666,7 @@ impl NaiveDateTime {
/// ```
/// # use chrono::{TimeDelta, NaiveDate};
/// # let hms = |h, m, s| NaiveDate::from_ymd_opt(2016, 7, 8).unwrap().and_hms_opt(h, m, s).unwrap();
/// assert_eq!(hms(3, 5, 7).checked_sub_signed(TimeDelta::days(1_000_000_000)), None);
/// assert_eq!(hms(3, 5, 7).checked_sub_signed(TimeDelta::try_days(1_000_000_000).unwrap()), None);
/// ```
///
/// Leap seconds are handled,
Expand All @@ -685,7 +685,7 @@ impl NaiveDateTime {
/// Some(hmsm(3, 5, 59, 800)));
/// assert_eq!(leap.checked_sub_signed(TimeDelta::seconds(60)),
/// Some(hmsm(3, 5, 0, 300)));
/// assert_eq!(leap.checked_sub_signed(TimeDelta::days(1)),
/// assert_eq!(leap.checked_sub_signed(TimeDelta::try_days(1).unwrap()),
/// Some(from_ymd(2016, 7, 7).and_hms_milli_opt(3, 6, 0, 300).unwrap()));
/// ```
#[must_use]
Expand Down Expand Up @@ -1586,7 +1586,7 @@ impl Timelike for NaiveDateTime {
/// from_ymd(2016, 7, 9).and_hms_opt(3, 5, 7).unwrap()
/// );
/// assert_eq!(
/// hms(3, 5, 7) + TimeDelta::days(365),
/// hms(3, 5, 7) + TimeDelta::try_days(365).unwrap(),
/// from_ymd(2017, 7, 8).and_hms_opt(3, 5, 7).unwrap()
/// );
///
Expand All @@ -1608,7 +1608,7 @@ impl Timelike for NaiveDateTime {
/// assert_eq!(leap + TimeDelta::milliseconds(800), hmsm(3, 6, 0, 100));
/// assert_eq!(leap + TimeDelta::seconds(10), hmsm(3, 6, 9, 300));
/// assert_eq!(leap + TimeDelta::seconds(-10), hmsm(3, 5, 50, 300));
/// assert_eq!(leap + TimeDelta::days(1),
/// assert_eq!(leap + TimeDelta::try_days(1).unwrap(),
/// from_ymd(2016, 7, 9).and_hms_milli_opt(3, 5, 59, 300).unwrap());
/// ```
///
Expand Down Expand Up @@ -1776,7 +1776,7 @@ impl Add<Months> for NaiveDateTime {
/// from_ymd(2016, 7, 7).and_hms_opt(3, 5, 7).unwrap()
/// );
/// assert_eq!(
/// hms(3, 5, 7) - TimeDelta::days(365),
/// hms(3, 5, 7) - TimeDelta::try_days(365).unwrap(),
/// from_ymd(2015, 7, 9).and_hms_opt(3, 5, 7).unwrap()
/// );
///
Expand All @@ -1796,7 +1796,7 @@ impl Add<Months> for NaiveDateTime {
/// assert_eq!(leap - TimeDelta::milliseconds(200), hmsm(3, 5, 59, 1_100));
/// assert_eq!(leap - TimeDelta::milliseconds(500), hmsm(3, 5, 59, 800));
/// assert_eq!(leap - TimeDelta::seconds(60), hmsm(3, 5, 0, 300));
/// assert_eq!(leap - TimeDelta::days(1),
/// assert_eq!(leap - TimeDelta::try_days(1).unwrap(),
/// from_ymd(2016, 7, 7).and_hms_milli_opt(3, 6, 0, 300).unwrap());
/// ```
///
Expand Down
4 changes: 2 additions & 2 deletions src/naive/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn test_datetime_addassignment() {
let mut date = ymdhms(2016, 10, 1, 10, 10, 10);
date += TimeDelta::minutes(10_000_000);
assert_eq!(date, ymdhms(2035, 10, 6, 20, 50, 10));
date += TimeDelta::days(10);
date += TimeDelta::try_days(10).unwrap();
assert_eq!(date, ymdhms(2035, 10, 16, 20, 50, 10));
}

Expand All @@ -86,7 +86,7 @@ fn test_datetime_subassignment() {
let mut date = ymdhms(2016, 10, 1, 10, 10, 10);
date -= TimeDelta::minutes(10_000_000);
assert_eq!(date, ymdhms(1997, 9, 26, 23, 30, 10));
date -= TimeDelta::days(10);
date -= TimeDelta::try_days(10).unwrap();
assert_eq!(date, ymdhms(1997, 9, 16, 23, 30, 10));
}

Expand Down
8 changes: 4 additions & 4 deletions src/naive/time/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ impl Timelike for NaiveTime {
/// # let from_hmsm = |h, m, s, milli| { NaiveTime::from_hms_milli_opt(h, m, s, milli).unwrap() };
/// assert_eq!(from_hmsm(3, 5, 7, 0) + TimeDelta::seconds(22*60*60), from_hmsm(1, 5, 7, 0));
/// assert_eq!(from_hmsm(3, 5, 7, 0) + TimeDelta::seconds(-8*60*60), from_hmsm(19, 5, 7, 0));
/// assert_eq!(from_hmsm(3, 5, 7, 0) + TimeDelta::days(800), from_hmsm(3, 5, 7, 0));
/// assert_eq!(from_hmsm(3, 5, 7, 0) + TimeDelta::try_days(800).unwrap(), from_hmsm(3, 5, 7, 0));
/// ```
///
/// Leap seconds are handled, but the addition assumes that it is the only leap second happened.
Expand All @@ -1181,7 +1181,7 @@ impl Timelike for NaiveTime {
/// assert_eq!(leap + TimeDelta::milliseconds(800), from_hmsm(3, 6, 0, 100));
/// assert_eq!(leap + TimeDelta::seconds(10), from_hmsm(3, 6, 9, 300));
/// assert_eq!(leap + TimeDelta::seconds(-10), from_hmsm(3, 5, 50, 300));
/// assert_eq!(leap + TimeDelta::days(1), from_hmsm(3, 5, 59, 300));
/// assert_eq!(leap + TimeDelta::try_days(1).unwrap(), from_hmsm(3, 5, 59, 300));
/// ```
///
/// [leap second handling]: crate::NaiveTime#leap-second-handling
Expand Down Expand Up @@ -1281,7 +1281,7 @@ impl Add<FixedOffset> for NaiveTime {
/// # use chrono::{TimeDelta, NaiveTime};
/// # let from_hmsm = |h, m, s, milli| { NaiveTime::from_hms_milli_opt(h, m, s, milli).unwrap() };
/// assert_eq!(from_hmsm(3, 5, 7, 0) - TimeDelta::seconds(8*60*60), from_hmsm(19, 5, 7, 0));
/// assert_eq!(from_hmsm(3, 5, 7, 0) - TimeDelta::days(800), from_hmsm(3, 5, 7, 0));
/// assert_eq!(from_hmsm(3, 5, 7, 0) - TimeDelta::try_days(800).unwrap(), from_hmsm(3, 5, 7, 0));
/// ```
///
/// Leap seconds are handled, but the subtraction assumes that it is the only leap second happened.
Expand All @@ -1294,7 +1294,7 @@ impl Add<FixedOffset> for NaiveTime {
/// assert_eq!(leap - TimeDelta::milliseconds(200), from_hmsm(3, 5, 59, 1_100));
/// assert_eq!(leap - TimeDelta::milliseconds(500), from_hmsm(3, 5, 59, 800));
/// assert_eq!(leap - TimeDelta::seconds(60), from_hmsm(3, 5, 0, 300));
/// assert_eq!(leap - TimeDelta::days(1), from_hmsm(3, 6, 0, 300));
/// assert_eq!(leap - TimeDelta::try_days(1).unwrap(), from_hmsm(3, 6, 0, 300));
/// ```
///
/// [leap second handling]: crate::NaiveTime#leap-second-handling
Expand Down
Loading

0 comments on commit 9f23c08

Please sign in to comment.