diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index f53b3c953a..b25058ffe6 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -307,7 +307,7 @@ fn test_nanosecond_range() { // Far beyond range let maximum = "2262-04-11T23:47:16.854775804UTC"; let parsed: DateTime = maximum.parse().unwrap(); - let beyond_max = parsed + TimeDelta::days(365); + let beyond_max = parsed + Days::new(365); assert!(beyond_max.timestamp_nanos_opt().is_none()); } @@ -1455,20 +1455,16 @@ fn test_datetime_before_windows_api_limits() { #[test] #[cfg(feature = "clock")] fn test_years_elapsed() { - const WEEKS_PER_YEAR: f32 = 52.1775; - - // This is always at least one year because 1 year = 52.1775 weeks. - let one_year_ago = - Utc::now().date_naive() - TimeDelta::weeks((WEEKS_PER_YEAR * 1.5).ceil() as i64); - // A bit more than 2 years. - let two_year_ago = - Utc::now().date_naive() - TimeDelta::weeks((WEEKS_PER_YEAR * 2.5).ceil() as i64); + // A bit more than 1 year + let one_year_ago = Utc::now().date_naive() - Days::new(400); + // A bit more than 2 years + let two_year_ago = Utc::now().date_naive() - Days::new(750); assert_eq!(Utc::now().date_naive().years_since(one_year_ago), Some(1)); assert_eq!(Utc::now().date_naive().years_since(two_year_ago), Some(2)); // If the given DateTime is later than now, the function will always return 0. - let future = Utc::now().date_naive() + TimeDelta::weeks(12); + let future = Utc::now().date_naive() + Days(100); assert_eq!(Utc::now().date_naive().years_since(future), None); } diff --git a/src/offset/local/mod.rs b/src/offset/local/mod.rs index b379b39e46..3b71a9a0ab 100644 --- a/src/offset/local/mod.rs +++ b/src/offset/local/mod.rs @@ -273,7 +273,7 @@ mod tests { #[cfg(windows)] use crate::offset::local::{lookup_with_dst_transitions, Transition}; use crate::offset::TimeZone; - use crate::{Datelike, TimeDelta, Utc}; + use crate::{Datelike, Days, Utc}; #[cfg(windows)] use crate::{FixedOffset, LocalResult, NaiveDate, NaiveDateTime}; @@ -292,7 +292,7 @@ mod tests { #[test] fn verify_correct_offsets_distant_past() { - let distant_past = Local::now() - TimeDelta::days(365 * 500); + let distant_past = Local::now() - Days::new(365 * 500); let from_local = Local.from_local_datetime(&distant_past.naive_local()).unwrap(); let from_utc = Local.from_utc_datetime(&distant_past.naive_utc()); @@ -305,7 +305,7 @@ mod tests { #[test] fn verify_correct_offsets_distant_future() { - let distant_future = Local::now() + TimeDelta::days(365 * 35000); + let distant_future = Local::now() + Days::new(365 * 35000); let from_local = Local.from_local_datetime(&distant_future.naive_local()).unwrap(); let from_utc = Local.from_utc_datetime(&distant_future.naive_utc()); diff --git a/src/traits.rs b/src/traits.rs index ae6cde494f..e582093b0b 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -330,7 +330,7 @@ pub trait Timelike: Sized { #[cfg(test)] mod tests { use super::Datelike; - use crate::{NaiveDate, TimeDelta}; + use crate::{Days, NaiveDate}; /// Tests `Datelike::num_days_from_ce` against an alternative implementation. /// @@ -377,7 +377,7 @@ mod tests { "on {:?}", jan1_year ); - let mid_year = jan1_year + TimeDelta::days(133); + let mid_year = jan1_year + Days::new(133); assert_eq!( mid_year.num_days_from_ce(), num_days_from_ce(&mid_year), diff --git a/tests/dateutils.rs b/tests/dateutils.rs index cf3d908a4b..c833c9fe20 100644 --- a/tests/dateutils.rs +++ b/tests/dateutils.rs @@ -157,6 +157,6 @@ fn try_verify_against_date_command_format() { let mut date = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_opt(12, 11, 13).unwrap(); while date.year() < 2008 { verify_against_date_command_format_local(DATE_PATH, date); - date += chrono::TimeDelta::days(55); + date = date + Days::new(55); } }