mirror of
https://github.com/chronotope/chrono.git
synced 2025-09-30 22:42:08 +00:00
Rename NaiveDateTime::and_local_timezone
to in_timezone
This commit is contained in:
parent
16462e2a8c
commit
af7c9f9f5d
@ -64,7 +64,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
|
|||||||
/// passing it through FFI.
|
/// passing it through FFI.
|
||||||
///
|
///
|
||||||
/// For regular use you will probably want to use a method such as
|
/// 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
|
/// # Example
|
||||||
///
|
///
|
||||||
@ -337,7 +337,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
|
|||||||
// datetime.
|
// datetime.
|
||||||
self.overflowing_naive_local()
|
self.overflowing_naive_local()
|
||||||
.checked_add_months(months)?
|
.checked_add_months(months)?
|
||||||
.and_local_timezone(Tz::from_offset(&self.offset))
|
.in_timezone(self.timezone())
|
||||||
.single()
|
.single()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +374,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
|
|||||||
// datetime.
|
// datetime.
|
||||||
self.overflowing_naive_local()
|
self.overflowing_naive_local()
|
||||||
.checked_sub_months(months)?
|
.checked_sub_months(months)?
|
||||||
.and_local_timezone(Tz::from_offset(&self.offset))
|
.in_timezone(self.timezone())
|
||||||
.single()
|
.single()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,12 +693,12 @@ impl NaiveDateTime {
|
|||||||
/// .unwrap()
|
/// .unwrap()
|
||||||
/// .at_hms(23, 56, 4)
|
/// .at_hms(23, 56, 4)
|
||||||
/// .unwrap()
|
/// .unwrap()
|
||||||
/// .and_local_timezone(tz)
|
/// .in_timezone(tz)
|
||||||
/// .unwrap();
|
/// .unwrap();
|
||||||
/// assert_eq!(dt.timezone(), tz);
|
/// assert_eq!(dt.timezone(), tz);
|
||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[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)
|
tz.from_local_datetime(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,14 +269,14 @@ fn test_datetime_add_sub_invariant() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[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 ndt = NaiveDate::from_ymd(2022, 6, 15).unwrap().at_hms(18, 59, 36).unwrap();
|
||||||
let dt_utc = ndt.and_utc();
|
let dt_utc = ndt.and_utc();
|
||||||
assert_eq!(dt_utc.naive_local(), ndt);
|
assert_eq!(dt_utc.naive_local(), ndt);
|
||||||
assert_eq!(dt_utc.timezone(), Utc);
|
assert_eq!(dt_utc.timezone(), Utc);
|
||||||
|
|
||||||
let offset_tz = FixedOffset::west(4 * 3600).unwrap();
|
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.naive_local(), ndt);
|
||||||
assert_eq!(dt_offset.timezone(), offset_tz);
|
assert_eq!(dt_offset.timezone(), offset_tz);
|
||||||
}
|
}
|
||||||
@ -381,13 +381,13 @@ fn test_and_timezone_min_max_dates() {
|
|||||||
dbg!(offset_hour);
|
dbg!(offset_hour);
|
||||||
let offset = FixedOffset::east(offset_hour * 60 * 60).unwrap();
|
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 {
|
if offset_hour >= 0 {
|
||||||
assert_eq!(local_max.unwrap().naive_local(), NaiveDateTime::MAX);
|
assert_eq!(local_max.unwrap().naive_local(), NaiveDateTime::MAX);
|
||||||
} else {
|
} else {
|
||||||
assert_eq!(local_max, MappedLocalTime::None);
|
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 {
|
if offset_hour <= 0 {
|
||||||
assert_eq!(local_min.unwrap().naive_local(), NaiveDateTime::MIN);
|
assert_eq!(local_min.unwrap().naive_local(), NaiveDateTime::MIN);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user