diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 418331e3..fc28ffa1 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -64,7 +64,7 @@ impl DateTime { /// passing it through FFI. /// /// For regular use you will probably want to use a method such as - /// [`TimeZone::from_local_datetime`] or [`NaiveDateTime::and_local_timezone`] instead. + /// [`TimeZone::from_local_datetime`] or [`NaiveDateTime::in_timezone`] instead. /// /// # Example /// @@ -337,7 +337,7 @@ impl DateTime { // datetime. self.overflowing_naive_local() .checked_add_months(months)? - .and_local_timezone(Tz::from_offset(&self.offset)) + .in_timezone(self.timezone()) .single() } @@ -374,7 +374,7 @@ impl DateTime { // datetime. self.overflowing_naive_local() .checked_sub_months(months)? - .and_local_timezone(Tz::from_offset(&self.offset)) + .in_timezone(self.timezone()) .single() } diff --git a/src/naive/datetime/mod.rs b/src/naive/datetime/mod.rs index ec146917..6ca08816 100644 --- a/src/naive/datetime/mod.rs +++ b/src/naive/datetime/mod.rs @@ -693,12 +693,12 @@ impl NaiveDateTime { /// .unwrap() /// .at_hms(23, 56, 4) /// .unwrap() - /// .and_local_timezone(tz) + /// .in_timezone(tz) /// .unwrap(); /// assert_eq!(dt.timezone(), tz); /// ``` #[must_use] - pub fn and_local_timezone(self, tz: Tz) -> MappedLocalTime> { + pub fn in_timezone(self, tz: Tz) -> MappedLocalTime> { tz.from_local_datetime(self) } diff --git a/src/naive/datetime/tests.rs b/src/naive/datetime/tests.rs index 20ddce00..a0eef36b 100644 --- a/src/naive/datetime/tests.rs +++ b/src/naive/datetime/tests.rs @@ -269,14 +269,14 @@ fn test_datetime_add_sub_invariant() { } #[test] -fn test_and_local_timezone() { +fn test_in_timezone() { let ndt = NaiveDate::from_ymd(2022, 6, 15).unwrap().at_hms(18, 59, 36).unwrap(); let dt_utc = ndt.and_utc(); assert_eq!(dt_utc.naive_local(), ndt); assert_eq!(dt_utc.timezone(), Utc); let offset_tz = FixedOffset::west(4 * 3600).unwrap(); - let dt_offset = ndt.and_local_timezone(offset_tz).unwrap(); + let dt_offset = ndt.in_timezone(offset_tz).unwrap(); assert_eq!(dt_offset.naive_local(), ndt); assert_eq!(dt_offset.timezone(), offset_tz); } @@ -381,13 +381,13 @@ fn test_and_timezone_min_max_dates() { dbg!(offset_hour); let offset = FixedOffset::east(offset_hour * 60 * 60).unwrap(); - let local_max = NaiveDateTime::MAX.and_local_timezone(offset); + let local_max = NaiveDateTime::MAX.in_timezone(offset); if offset_hour >= 0 { assert_eq!(local_max.unwrap().naive_local(), NaiveDateTime::MAX); } else { assert_eq!(local_max, MappedLocalTime::None); } - let local_min = NaiveDateTime::MIN.and_local_timezone(offset); + let local_min = NaiveDateTime::MIN.in_timezone(offset); if offset_hour <= 0 { assert_eq!(local_min.unwrap().naive_local(), NaiveDateTime::MIN); } else {