From 16462e2a8c3e8f755bd15de6df67255bcd74dc8d Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Mon, 18 Mar 2024 19:02:29 +0100 Subject: [PATCH] Rename `NaiveDate::and_time` to `DateTime::at` --- src/datetime/mod.rs | 4 ++-- src/datetime/tests.rs | 22 +++++++++++----------- src/format/formatting.rs | 8 ++++---- src/format/parsed.rs | 4 ++-- src/naive/date/mod.rs | 12 ++++++------ src/naive/datetime/mod.rs | 4 ++-- src/offset/local/windows.rs | 4 ++-- tests/dateutils.rs | 4 ++-- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 93bd1752..418331e3 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -648,7 +648,7 @@ impl DateTime { /// ``` #[must_use] pub fn with_time(&self, time: NaiveTime) -> MappedLocalTime { - self.timezone().from_local_datetime(self.overflowing_naive_local().date().and_time(time)) + self.timezone().from_local_datetime(self.overflowing_naive_local().date().at(time)) } /// Makes a new `DateTime` with the hour number changed. @@ -761,7 +761,7 @@ impl DateTime { } let date = try_err!(NaiveDate::from_num_days_from_ce(days as i32)); let time = try_err!(NaiveTime::from_num_seconds_from_midnight(secs as u32, nsecs)); - Ok(date.and_time(time).and_utc()) + Ok(date.at(time).and_utc()) } /// Makes a new `DateTime` from the number of non-leap milliseconds diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index 5d6c5f69..e47dc4be 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -43,7 +43,7 @@ impl TimeZone for DstTester { DstTester::TO_WINTER_MONTH_DAY.1, ) .unwrap() - .and_time(DstTester::transition_start_local()); + .at(DstTester::transition_start_local()); let local_to_winter_transition_end = NaiveDate::from_ymd( local.year(), @@ -51,7 +51,7 @@ impl TimeZone for DstTester { DstTester::TO_WINTER_MONTH_DAY.1, ) .unwrap() - .and_time(DstTester::transition_start_local() - TimeDelta::hours(1)); + .at(DstTester::transition_start_local() - TimeDelta::hours(1)); let local_to_summer_transition_start = NaiveDate::from_ymd( local.year(), @@ -59,7 +59,7 @@ impl TimeZone for DstTester { DstTester::TO_SUMMER_MONTH_DAY.1, ) .unwrap() - .and_time(DstTester::transition_start_local()); + .at(DstTester::transition_start_local()); let local_to_summer_transition_end = NaiveDate::from_ymd( local.year(), @@ -67,7 +67,7 @@ impl TimeZone for DstTester { DstTester::TO_SUMMER_MONTH_DAY.1, ) .unwrap() - .and_time(DstTester::transition_start_local() + TimeDelta::hours(1)); + .at(DstTester::transition_start_local() + TimeDelta::hours(1)); if local < local_to_winter_transition_end || local >= local_to_summer_transition_end { MappedLocalTime::Single(DstTester::summer_offset()) @@ -95,7 +95,7 @@ impl TimeZone for DstTester { DstTester::TO_WINTER_MONTH_DAY.1, ) .unwrap() - .and_time(DstTester::transition_start_local()) + .at(DstTester::transition_start_local()) - DstTester::summer_offset(); let utc_to_summer_transition = NaiveDate::from_ymd( @@ -104,7 +104,7 @@ impl TimeZone for DstTester { DstTester::TO_SUMMER_MONTH_DAY.1, ) .unwrap() - .and_time(DstTester::transition_start_local()) + .at(DstTester::transition_start_local()) - DstTester::winter_offset(); if utc < utc_to_winter_transition || utc >= utc_to_summer_transition { @@ -597,7 +597,7 @@ fn signed_duration_since_autoref() { } #[test] -fn test_datetime_date_and_time() { +fn test_datetime_date_at() { let tz = FixedOffset::east(5 * 60 * 60).unwrap(); let d = tz.at_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap(); assert_eq!(d.time(), NaiveTime::from_hms(7, 8, 9).unwrap()); @@ -1542,7 +1542,7 @@ fn test_min_max_add_days() { assert_eq!(beyond_min.checked_add_days(Days::new(0)), Some(beyond_min)); assert_eq!( beyond_min.checked_add_days(Days::new(1)), - Some(offset_min.from_utc_datetime((NaiveDate::MIN + Days(1)).and_time(NaiveTime::MIN))) + Some(offset_min.from_utc_datetime((NaiveDate::MIN + Days(1)).at(NaiveTime::MIN))) ); assert_eq!(beyond_min.checked_sub_days(Days::new(0)), Some(beyond_min)); assert_eq!(beyond_min.checked_sub_days(Days::new(1)), None); @@ -1552,7 +1552,7 @@ fn test_min_max_add_days() { assert_eq!(beyond_max.checked_sub_days(Days::new(0)), Some(beyond_max)); assert_eq!( beyond_max.checked_sub_days(Days::new(1)), - Some(offset_max.from_utc_datetime((NaiveDate::MAX - Days(1)).and_time(max_time))) + Some(offset_max.from_utc_datetime((NaiveDate::MAX - Days(1)).at(max_time))) ); } @@ -1567,7 +1567,7 @@ fn test_min_max_add_months() { assert_eq!(beyond_min.checked_add_months(Months::new(0)), Some(beyond_min)); assert_eq!( beyond_min.checked_add_months(Months::new(1)), - Some(offset_min.from_utc_datetime((NaiveDate::MIN + Months(1)).and_time(NaiveTime::MIN))) + Some(offset_min.from_utc_datetime((NaiveDate::MIN + Months(1)).at(NaiveTime::MIN))) ); assert_eq!(beyond_min.checked_sub_months(Months::new(0)), Some(beyond_min)); assert_eq!(beyond_min.checked_sub_months(Months::new(1)), None); @@ -1577,7 +1577,7 @@ fn test_min_max_add_months() { assert_eq!(beyond_max.checked_sub_months(Months::new(0)), Some(beyond_max)); assert_eq!( beyond_max.checked_sub_months(Months::new(1)), - Some(offset_max.from_utc_datetime((NaiveDate::MAX - Months(1)).and_time(max_time))) + Some(offset_max.from_utc_datetime((NaiveDate::MAX - Months(1)).at(max_time))) ); } diff --git a/src/format/formatting.rs b/src/format/formatting.rs index a8d012bc..0c7a3e70 100644 --- a/src/format/formatting.rs +++ b/src/format/formatting.rs @@ -182,10 +182,10 @@ fn format_inner( Timestamp => ( 1, match (date, time, off) { - (Some(d), Some(t), None) => Some(d.and_time(*t).and_utc().timestamp()), - (Some(d), Some(t), Some(&(_, off))) => Some( - d.and_time(*t).and_utc().timestamp() - i64::from(off.local_minus_utc()), - ), + (Some(d), Some(t), None) => Some(d.at(*t).and_utc().timestamp()), + (Some(d), Some(t), Some(&(_, off))) => { + Some(d.at(*t).and_utc().timestamp() - i64::from(off.local_minus_utc())) + } (_, _, _) => None, }, ), diff --git a/src/format/parsed.rs b/src/format/parsed.rs index e03b24db..c59ca9d4 100644 --- a/src/format/parsed.rs +++ b/src/format/parsed.rs @@ -752,7 +752,7 @@ impl Parsed { let date = self.to_naive_date(); let time = self.to_naive_time(); if let (Ok(date), Ok(time)) = (date, time) { - let datetime = date.and_time(time); + let datetime = date.at(time); // verify the timestamp field if any // the following is safe, `timestamp` is very limited in range @@ -814,7 +814,7 @@ impl Parsed { // validate other fields (e.g. week) and return let date = parsed.to_naive_date()?; let time = parsed.to_naive_time()?; - Ok(date.and_time(time)) + Ok(date.at(time)) } else { // reproduce the previous error(s) date?; diff --git a/src/naive/date/mod.rs b/src/naive/date/mod.rs index f271d9f0..c96030fd 100644 --- a/src/naive/date/mod.rs +++ b/src/naive/date/mod.rs @@ -623,13 +623,13 @@ impl NaiveDate { /// let d = NaiveDate::from_ymd(2015, 6, 3).unwrap(); /// let t = NaiveTime::from_hms_milli(12, 34, 56, 789).unwrap(); /// - /// let dt: NaiveDateTime = d.and_time(t); + /// let dt: NaiveDateTime = d.at(t); /// assert_eq!(dt.date(), d); /// assert_eq!(dt.time(), t); /// ``` #[inline] #[must_use] - pub const fn and_time(self, time: NaiveTime) -> NaiveDateTime { + pub const fn at(self, time: NaiveTime) -> NaiveDateTime { NaiveDateTime::new(self, time) } @@ -656,7 +656,7 @@ impl NaiveDate { #[inline] pub const fn at_hms(self, hour: u32, min: u32, sec: u32) -> Result { let time = try_err!(NaiveTime::from_hms(hour, min, sec)); - Ok(self.and_time(time)) + Ok(self.at(time)) } /// Makes a new `NaiveDateTime` from the current date, hour, minute, second and millisecond. @@ -693,7 +693,7 @@ impl NaiveDate { milli: u32, ) -> Result { let time = try_err!(NaiveTime::from_hms_milli(hour, min, sec, milli)); - Ok(self.and_time(time)) + Ok(self.at(time)) } /// Makes a new `NaiveDateTime` from the current date, hour, minute, second and microsecond. @@ -730,7 +730,7 @@ impl NaiveDate { micro: u32, ) -> Result { let time = try_err!(NaiveTime::from_hms_micro(hour, min, sec, micro)); - Ok(self.and_time(time)) + Ok(self.at(time)) } /// Makes a new `NaiveDateTime` from the current date, hour, minute, second and nanosecond. @@ -767,7 +767,7 @@ impl NaiveDate { nano: u32, ) -> Result { let time = try_err!(NaiveTime::from_hms_nano(hour, min, sec, nano)); - Ok(self.and_time(time)) + Ok(self.at(time)) } /// Returns the packed month-day-flags. diff --git a/src/naive/datetime/mod.rs b/src/naive/datetime/mod.rs index ae0cef2a..ec146917 100644 --- a/src/naive/datetime/mod.rs +++ b/src/naive/datetime/mod.rs @@ -71,7 +71,7 @@ pub struct NaiveDateTime { impl NaiveDateTime { /// Makes a new `NaiveDateTime` from date and time components. - /// Equivalent to [`date.and_time(time)`](./struct.NaiveDate.html#method.and_time) + /// Equivalent to [`date.at(time)`](./struct.NaiveDate.html#method.at) /// and many other helper constructors on `NaiveDate`. /// /// # Example @@ -939,7 +939,7 @@ impl NaiveDateTime { /// The Unix Epoch, 1970-01-01 00:00:00. pub const UNIX_EPOCH: Self = - expect(ok!(NaiveDate::from_ymd(1970, 1, 1)), "").and_time(NaiveTime::MIN); + expect(ok!(NaiveDate::from_ymd(1970, 1, 1)), "").at(NaiveTime::MIN); } impl From for NaiveDateTime { diff --git a/src/offset/local/windows.rs b/src/offset/local/windows.rs index 6dd7a0c0..59bd6568 100644 --- a/src/offset/local/windows.rs +++ b/src/offset/local/windows.rs @@ -187,7 +187,7 @@ fn naive_date_time_from_system_time( // We have a concrete date. let date = NaiveDate::from_ymd(st.wYear as i32, st.wMonth as u32, st.wDay as u32) .map_err(|_| ())?; - return Ok(Some(date.and_time(time))); + return Ok(Some(date.at(time))); } // Resolve a rule with month, weekday, and nth weekday of the month to a date in the current @@ -213,7 +213,7 @@ fn naive_date_time_from_system_time( } Err(_) => return Err(()), // `st.wMonth` must be invalid }; - Ok(Some(date.and_time(time))) + Ok(Some(date.at(time))) } #[cfg(test)] diff --git a/tests/dateutils.rs b/tests/dateutils.rs index b33bc198..d5415e9e 100644 --- a/tests/dateutils.rs +++ b/tests/dateutils.rs @@ -90,8 +90,8 @@ fn try_verify_against_date_command() { let mut children = vec![]; for year in [1975, 1976, 1977, 2020, 2021, 2022, 2073, 2074, 2075, 2076, 2077].iter() { children.push(thread::spawn(|| { - let mut date = NaiveDate::from_ymd(*year, 1, 1).unwrap().and_time(NaiveTime::MIN); - let end = NaiveDate::from_ymd(*year + 1, 1, 1).unwrap().and_time(NaiveTime::MIN); + let mut date = NaiveDate::from_ymd(*year, 1, 1).unwrap().at(NaiveTime::MIN); + let end = NaiveDate::from_ymd(*year + 1, 1, 1).unwrap().at(NaiveTime::MIN); while date <= end { verify_against_date_command_local(DATE_PATH, date); date += chrono::TimeDelta::hours(1);