Skip to content

Commit

Permalink
Rename NaiveDateTime::and_local_timezone to in_timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Mar 18, 2024
1 parent 4d0f580 commit 5f5188c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
/// 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
///
Expand Down Expand Up @@ -337,7 +337,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
// datetime.
self.overflowing_naive_local()
.checked_add_months(months)?
.and_local_timezone(Tz::from_offset(&self.offset))
.in_timezone(self.timezone())
.single()
}

Expand Down Expand Up @@ -374,7 +374,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
// datetime.
self.overflowing_naive_local()
.checked_sub_months(months)?
.and_local_timezone(Tz::from_offset(&self.offset))
.in_timezone(self.timezone())
.single()
}

Expand Down
4 changes: 2 additions & 2 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,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<Tz: TimeZone>(self, tz: Tz) -> MappedLocalTime<DateTime<Tz>> {
pub fn in_timezone<Tz: TimeZone>(self, tz: Tz) -> MappedLocalTime<DateTime<Tz>> {
tz.from_local_datetime(self)
}

Expand Down
8 changes: 4 additions & 4 deletions src/naive/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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().unwrap();
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);
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5f5188c

Please sign in to comment.