diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index fc28ffa134..da94f5037d 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -151,10 +151,10 @@ impl DateTime { /// ``` /// use chrono::NaiveDate; /// - /// let dt = NaiveDate::from_ymd(1970, 1, 1)?.at_hms_milli(0, 0, 1, 444)?.and_utc(); + /// let dt = NaiveDate::from_ymd(1970, 1, 1)?.at_hms_milli(0, 0, 1, 444)?.in_utc(); /// assert_eq!(dt.timestamp_millis(), 1_444); /// - /// let dt = NaiveDate::from_ymd(2001, 9, 9)?.at_hms_milli(1, 46, 40, 555)?.and_utc(); + /// let dt = NaiveDate::from_ymd(2001, 9, 9)?.at_hms_milli(1, 46, 40, 555)?.in_utc(); /// assert_eq!(dt.timestamp_millis(), 1_000_000_000_555); /// # Ok::<(), chrono::Error>(()) /// ``` @@ -172,10 +172,10 @@ impl DateTime { /// ``` /// use chrono::NaiveDate; /// - /// let dt = NaiveDate::from_ymd(1970, 1, 1)?.at_hms_micro(0, 0, 1, 444)?.and_utc(); + /// let dt = NaiveDate::from_ymd(1970, 1, 1)?.at_hms_micro(0, 0, 1, 444)?.in_utc(); /// assert_eq!(dt.timestamp_micros(), 1_000_444); /// - /// let dt = NaiveDate::from_ymd(2001, 9, 9)?.at_hms_micro(1, 46, 40, 555)?.and_utc(); + /// let dt = NaiveDate::from_ymd(2001, 9, 9)?.at_hms_micro(1, 46, 40, 555)?.in_utc(); /// assert_eq!(dt.timestamp_micros(), 1_000_000_000_000_555); /// # Ok::<(), chrono::Error>(()) /// ``` @@ -201,22 +201,22 @@ impl DateTime { /// ``` /// use chrono::{Error, NaiveDate}; /// - /// let dt = NaiveDate::from_ymd(1970, 1, 1)?.at_hms_nano(0, 0, 1, 444)?.and_utc(); + /// let dt = NaiveDate::from_ymd(1970, 1, 1)?.at_hms_nano(0, 0, 1, 444)?.in_utc(); /// assert_eq!(dt.timestamp_nanos(), Ok(1_000_000_444)); /// - /// let dt = NaiveDate::from_ymd(2001, 9, 9)?.at_hms_nano(1, 46, 40, 555)?.and_utc(); + /// let dt = NaiveDate::from_ymd(2001, 9, 9)?.at_hms_nano(1, 46, 40, 555)?.in_utc(); /// assert_eq!(dt.timestamp_nanos(), Ok(1_000_000_000_000_000_555)); /// - /// let dt = NaiveDate::from_ymd(1677, 9, 21)?.at_hms_nano(0, 12, 43, 145_224_192)?.and_utc(); + /// let dt = NaiveDate::from_ymd(1677, 9, 21)?.at_hms_nano(0, 12, 43, 145_224_192)?.in_utc(); /// assert_eq!(dt.timestamp_nanos(), Ok(-9_223_372_036_854_775_808)); /// - /// let dt = NaiveDate::from_ymd(2262, 4, 11)?.at_hms_nano(23, 47, 16, 854_775_807)?.and_utc(); + /// let dt = NaiveDate::from_ymd(2262, 4, 11)?.at_hms_nano(23, 47, 16, 854_775_807)?.in_utc(); /// assert_eq!(dt.timestamp_nanos(), Ok(9_223_372_036_854_775_807)); /// - /// let dt = NaiveDate::from_ymd(1677, 9, 21)?.at_hms_nano(0, 12, 43, 145_224_191)?.and_utc(); + /// let dt = NaiveDate::from_ymd(1677, 9, 21)?.at_hms_nano(0, 12, 43, 145_224_191)?.in_utc(); /// assert_eq!(dt.timestamp_nanos(), Err(Error::OutOfRange)); /// - /// let dt = NaiveDate::from_ymd(2262, 4, 11)?.at_hms_nano(23, 47, 16, 854_775_808)?.and_utc(); + /// let dt = NaiveDate::from_ymd(2262, 4, 11)?.at_hms_nano(23, 47, 16, 854_775_808)?.in_utc(); /// assert_eq!(dt.timestamp_nanos(), Err(Error::OutOfRange)); /// # Ok::<(), Error>(()) /// ``` @@ -532,7 +532,7 @@ impl DateTime { /// .unwrap() /// .at_hms_micro(18, 30, 9, 453_829) /// .unwrap() - /// .and_utc(); + /// .in_utc(); /// assert_eq!(dt.to_rfc3339_opts(SecondsFormat::Millis, false), "2018-01-26T18:30:09.453+00:00"); /// assert_eq!(dt.to_rfc3339_opts(SecondsFormat::Millis, true), "2018-01-26T18:30:09.453Z"); /// assert_eq!(dt.to_rfc3339_opts(SecondsFormat::Secs, true), "2018-01-26T18:30:09Z"); @@ -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.at(time).and_utc()) + Ok(date.at(time).in_utc()) } /// Makes a new `DateTime` from the number of non-leap milliseconds diff --git a/src/datetime/serde.rs b/src/datetime/serde.rs index 96bf9a4a6c..944357349b 100644 --- a/src/datetime/serde.rs +++ b/src/datetime/serde.rs @@ -122,7 +122,7 @@ impl<'de> de::Deserialize<'de> for DateTime { /// .unwrap() /// .at_hms_nano(02, 04, 59, 918355733) /// .unwrap() -/// .and_utc(); +/// .in_utc(); /// let my_s = S { time: time.clone() }; /// /// let as_string = serde_json::to_string(&my_s)?; @@ -167,7 +167,7 @@ pub mod ts_nanoseconds { /// .unwrap() /// .at_hms_nano(02, 04, 59, 918355733) /// .unwrap() - /// .and_utc(), + /// .in_utc(), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355733}"#); @@ -265,7 +265,7 @@ pub mod ts_nanoseconds { /// .unwrap() /// .at_hms_nano(02, 04, 59, 918355733) /// .unwrap() -/// .and_utc(), +/// .in_utc(), /// ); /// let my_s = S { time: time.clone() }; /// @@ -313,7 +313,7 @@ pub mod ts_nanoseconds_option { /// .unwrap() /// .at_hms_nano(02, 04, 59, 918355733) /// .unwrap() - /// .and_utc(), + /// .in_utc(), /// ), /// }; /// let as_string = serde_json::to_string(&my_s)?; @@ -414,7 +414,7 @@ pub mod ts_nanoseconds_option { /// .unwrap() /// .at_hms_micro(02, 04, 59, 918355) /// .unwrap() -/// .and_utc(); +/// .in_utc(); /// let my_s = S { time: time.clone() }; /// /// let as_string = serde_json::to_string(&my_s)?; @@ -451,7 +451,7 @@ pub mod ts_microseconds { /// .unwrap() /// .at_hms_micro(02, 04, 59, 918355) /// .unwrap() - /// .and_utc(), + /// .in_utc(), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918355}"#); @@ -550,7 +550,7 @@ pub mod ts_microseconds { /// .unwrap() /// .at_hms_micro(02, 04, 59, 918355) /// .unwrap() -/// .and_utc(), +/// .in_utc(), /// ); /// let my_s = S { time: time.clone() }; /// @@ -589,7 +589,7 @@ pub mod ts_microseconds_option { /// .unwrap() /// .at_hms_micro(02, 04, 59, 918355) /// .unwrap() - /// .and_utc(), + /// .in_utc(), /// ), /// }; /// let as_string = serde_json::to_string(&my_s)?; @@ -685,7 +685,7 @@ pub mod ts_microseconds_option { /// } /// /// let time = -/// NaiveDate::from_ymd(2018, 5, 17).unwrap().at_hms_milli(02, 04, 59, 918).unwrap().and_utc(); +/// NaiveDate::from_ymd(2018, 5, 17).unwrap().at_hms_milli(02, 04, 59, 918).unwrap().in_utc(); /// let my_s = S { time: time.clone() }; /// /// let as_string = serde_json::to_string(&my_s)?; @@ -722,7 +722,7 @@ pub mod ts_milliseconds { /// .unwrap() /// .at_hms_milli(02, 04, 59, 918) /// .unwrap() - /// .and_utc(), + /// .in_utc(), /// }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1526522699918}"#); @@ -810,7 +810,7 @@ pub mod ts_milliseconds { /// } /// /// let time = Some( -/// NaiveDate::from_ymd(2018, 5, 17).unwrap().at_hms_milli(02, 04, 59, 918).unwrap().and_utc(), +/// NaiveDate::from_ymd(2018, 5, 17).unwrap().at_hms_milli(02, 04, 59, 918).unwrap().in_utc(), /// ); /// let my_s = S { time: time.clone() }; /// @@ -849,7 +849,7 @@ pub mod ts_milliseconds_option { /// .unwrap() /// .at_hms_milli(02, 04, 59, 918) /// .unwrap() - /// .and_utc(), + /// .in_utc(), /// ), /// }; /// let as_string = serde_json::to_string(&my_s)?; diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index e47dc4be84..122f21a6a2 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -245,7 +245,7 @@ fn test_datetime_from_timestamp_nanos() { fn test_datetime_from_timestamp() { let from_timestamp = |secs| DateTime::from_timestamp(secs, 0); let ymdhms = - |y, m, d, h, n, s| NaiveDate::from_ymd(y, m, d).unwrap().at_hms(h, n, s).unwrap().and_utc(); + |y, m, d, h, n, s| NaiveDate::from_ymd(y, m, d).unwrap().at_hms(h, n, s).unwrap().in_utc(); assert_eq!(from_timestamp(-1), Ok(ymdhms(1969, 12, 31, 23, 59, 59))); assert_eq!(from_timestamp(0), Ok(ymdhms(1970, 1, 1, 0, 0, 0))); assert_eq!(from_timestamp(1), Ok(ymdhms(1970, 1, 1, 0, 0, 1))); @@ -258,7 +258,7 @@ fn test_datetime_from_timestamp() { #[test] fn test_datetime_timestamp() { let to_timestamp = |y, m, d, h, n, s| { - NaiveDate::from_ymd(y, m, d).unwrap().at_hms(h, n, s).unwrap().and_utc().timestamp() + NaiveDate::from_ymd(y, m, d).unwrap().at_hms(h, n, s).unwrap().in_utc().timestamp() }; assert_eq!(to_timestamp(1969, 12, 31, 23, 59, 59), -1); assert_eq!(to_timestamp(1970, 1, 1, 0, 0, 0), 0); @@ -841,7 +841,7 @@ fn test_rfc3339_opts() { assert_eq!(dt.to_rfc3339_opts(Nanos, false), "2018-01-11T10:05:13.084660000+08:00"); assert_eq!(dt.to_rfc3339_opts(AutoSi, false), "2018-01-11T10:05:13.084660+08:00"); - let ut = dt.naive_utc().and_utc(); + let ut = dt.naive_utc().in_utc(); assert_eq!(ut.to_rfc3339_opts(Secs, false), "2018-01-11T02:05:13+00:00"); assert_eq!(ut.to_rfc3339_opts(Secs, true), "2018-01-11T02:05:13Z"); assert_eq!(ut.to_rfc3339_opts(Millis, false), "2018-01-11T02:05:13.084+00:00"); @@ -1379,7 +1379,7 @@ fn test_years_elapsed() { #[test] fn test_datetime_add_assign() { let naivedatetime = NaiveDate::from_ymd(2000, 1, 1).unwrap().at_hms(0, 0, 0).unwrap(); - let datetime = naivedatetime.and_utc(); + let datetime = naivedatetime.in_utc(); let mut datetime_add = datetime; datetime_add += TimeDelta::seconds(60); @@ -1416,7 +1416,7 @@ fn test_datetime_add_assign_local() { #[test] fn test_datetime_sub_assign() { let naivedatetime = NaiveDate::from_ymd(2000, 1, 1).unwrap().at_hms(12, 0, 0).unwrap(); - let datetime = naivedatetime.and_utc(); + let datetime = naivedatetime.in_utc(); let mut datetime_sub = datetime; datetime_sub -= TimeDelta::minutes(90); diff --git a/src/format/formatting.rs b/src/format/formatting.rs index 0c7a3e70bc..a349902365 100644 --- a/src/format/formatting.rs +++ b/src/format/formatting.rs @@ -182,9 +182,9 @@ fn format_inner( Timestamp => ( 1, match (date, time, off) { - (Some(d), Some(t), None) => Some(d.at(*t).and_utc().timestamp()), + (Some(d), Some(t), None) => Some(d.at(*t).in_utc().timestamp()), (Some(d), Some(t), Some(&(_, off))) => { - Some(d.at(*t).and_utc().timestamp() - i64::from(off.local_minus_utc())) + Some(d.at(*t).in_utc().timestamp() - i64::from(off.local_minus_utc())) } (_, _, _) => None, }, diff --git a/src/format/mod.rs b/src/format/mod.rs index 2f3bef5530..79eb0c6195 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -25,7 +25,7 @@ //! let formatted = format!("{}", date_time.format("%Y-%m-%d %H:%M:%S")); //! assert_eq!(formatted, "2020-11-10 00:01:32"); //! -//! let parsed = NaiveDateTime::parse_from_str(&formatted, "%Y-%m-%d %H:%M:%S")?.and_utc(); +//! let parsed = NaiveDateTime::parse_from_str(&formatted, "%Y-%m-%d %H:%M:%S")?.in_utc(); //! assert_eq!(parsed, date_time); //! # } //! # Ok::<(), chrono::ParseError>(()) diff --git a/src/format/parsed.rs b/src/format/parsed.rs index c59ca9d486..3627124d24 100644 --- a/src/format/parsed.rs +++ b/src/format/parsed.rs @@ -756,7 +756,7 @@ impl Parsed { // verify the timestamp field if any // the following is safe, `timestamp` is very limited in range - let timestamp = datetime.and_utc().timestamp() - i64::from(offset); + let timestamp = datetime.in_utc().timestamp() - i64::from(offset); if let Some(given_timestamp) = self.timestamp { // if `datetime` represents a leap second, it might be off by one second. if given_timestamp != timestamp diff --git a/src/lib.rs b/src/lib.rs index 4396857878..3e51564b45 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -131,35 +131,35 @@ //! dt, //! NaiveDate::from_ymd(2014, 7, 8)? //! .at_hms(9, 10, 11)? -//! .and_utc() +//! .in_utc() //! ); //! //! // July 8 is 188th day of the year 2014 (`o` for "ordinal") -//! assert_eq!(dt, NaiveDate::from_yo(2014, 189).unwrap().at_hms(9, 10, 11).unwrap().and_utc()); +//! assert_eq!(dt, NaiveDate::from_yo(2014, 189).unwrap().at_hms(9, 10, 11).unwrap().in_utc()); //! // July 8 is Tuesday in ISO week 28 of the year 2014. -//! assert_eq!(dt, NaiveDate::from_isoywd(2014, 28, Weekday::Tue).unwrap().at_hms(9, 10, 11).unwrap().and_utc()); +//! assert_eq!(dt, NaiveDate::from_isoywd(2014, 28, Weekday::Tue).unwrap().at_hms(9, 10, 11).unwrap().in_utc()); //! //! let dt = NaiveDate::from_ymd(2014, 7, 8)? //! .at_hms_milli(9, 10, 11, 12)? -//! .and_utc(); // `2014-07-08T09:10:11.012Z` +//! .in_utc(); // `2014-07-08T09:10:11.012Z` //! assert_eq!( //! dt, //! NaiveDate::from_ymd(2014, 7, 8)? //! .at_hms_micro(9, 10, 11, 12_000)? -//! .and_utc() +//! .in_utc() //! ); //! assert_eq!( //! dt, //! NaiveDate::from_ymd(2014, 7, 8)? //! .at_hms_nano(9, 10, 11, 12_000_000)? -//! .and_utc() +//! .in_utc() //! ); //! //! // dynamic verification //! assert_eq!( //! Utc.at_ymd_and_hms(2014, 7, 8, 21, 15, 33), //! MappedLocalTime::Single( -//! NaiveDate::from_ymd(2014, 7, 8)?.at_hms(21, 15, 33)?.and_utc() +//! NaiveDate::from_ymd(2014, 7, 8)?.at_hms(21, 15, 33)?.in_utc() //! ) //! ); //! assert_eq!(Utc.at_ymd_and_hms(2014, 7, 8, 80, 15, 33), MappedLocalTime::None); @@ -203,7 +203,7 @@ //! assert_eq!(dt.timezone(), FixedOffset::east(9 * 3600)?); //! assert_eq!( //! dt.with_timezone(&Utc), -//! NaiveDate::from_ymd(2014, 11, 28)?.at_hms_nano(12, 45, 59, 324310806)?.and_utc() +//! NaiveDate::from_ymd(2014, 11, 28)?.at_hms_nano(12, 45, 59, 324310806)?.in_utc() //! ); //! //! // a sample of property manipulations (validates dynamically) @@ -271,7 +271,7 @@ //! //! // Note that milli/nanoseconds are only printed if they are non-zero //! let dt_nano = -//! NaiveDate::from_ymd(2014, 11, 28).unwrap().at_hms_nano(12, 0, 9, 1).unwrap().and_utc(); +//! NaiveDate::from_ymd(2014, 11, 28).unwrap().at_hms_nano(12, 0, 9, 1).unwrap().in_utc(); //! assert_eq!(format!("{:?}", dt_nano), "2014-11-28T12:00:09.000000001Z"); //! # } //! # #[cfg(not(all(feature = "unstable-locales", feature = "alloc")))] diff --git a/src/naive/datetime/mod.rs b/src/naive/datetime/mod.rs index 6ca0881655..650b268046 100644 --- a/src/naive/datetime/mod.rs +++ b/src/naive/datetime/mod.rs @@ -708,11 +708,11 @@ impl NaiveDateTime { /// /// ``` /// use chrono::{NaiveDate, Utc}; - /// let dt = NaiveDate::from_ymd(2023, 1, 30).unwrap().at_hms(19, 32, 33).unwrap().and_utc(); + /// let dt = NaiveDate::from_ymd(2023, 1, 30).unwrap().at_hms(19, 32, 33).unwrap().in_utc(); /// assert_eq!(dt.timezone(), Utc); /// ``` #[must_use] - pub const fn and_utc(self) -> DateTime { + pub const fn in_utc(self) -> DateTime { DateTime::from_naive_utc_and_offset(self, Utc) } diff --git a/src/naive/datetime/serde.rs b/src/naive/datetime/serde.rs index 38257f997c..bdb5dea143 100644 --- a/src/naive/datetime/serde.rs +++ b/src/naive/datetime/serde.rs @@ -117,7 +117,7 @@ pub mod ts_nanoseconds { where S: ser::Serializer, { - serializer.serialize_i64(dt.and_utc().timestamp_nanos().map_err(|_| { + serializer.serialize_i64(dt.in_utc().timestamp_nanos().map_err(|_| { ser::Error::custom("value out of range for a timestamp with nanosecond precision") })?) } @@ -258,7 +258,7 @@ pub mod ts_nanoseconds_option { { match *opt { Some(ref dt) => { - serializer.serialize_some(&dt.and_utc().timestamp_nanos().map_err(|_| { + serializer.serialize_some(&dt.in_utc().timestamp_nanos().map_err(|_| { ser::Error::custom( "value out of range for a timestamp with nanosecond precision", ) @@ -392,7 +392,7 @@ pub mod ts_microseconds { where S: ser::Serializer, { - serializer.serialize_i64(dt.and_utc().timestamp_micros()) + serializer.serialize_i64(dt.in_utc().timestamp_micros()) } /// Deserialize a `NaiveDateTime` from a microseconds timestamp @@ -522,7 +522,7 @@ pub mod ts_microseconds_option { S: ser::Serializer, { match *opt { - Some(ref dt) => serializer.serialize_some(&dt.and_utc().timestamp_micros()), + Some(ref dt) => serializer.serialize_some(&dt.in_utc().timestamp_micros()), None => serializer.serialize_none(), } } @@ -651,7 +651,7 @@ pub mod ts_milliseconds { where S: ser::Serializer, { - serializer.serialize_i64(dt.and_utc().timestamp_millis()) + serializer.serialize_i64(dt.in_utc().timestamp_millis()) } /// Deserialize a `NaiveDateTime` from a milliseconds timestamp @@ -778,7 +778,7 @@ pub mod ts_milliseconds_option { S: ser::Serializer, { match *opt { - Some(ref dt) => serializer.serialize_some(&dt.and_utc().timestamp_millis()), + Some(ref dt) => serializer.serialize_some(&dt.in_utc().timestamp_millis()), None => serializer.serialize_none(), } } @@ -905,7 +905,7 @@ pub mod ts_seconds { where S: ser::Serializer, { - serializer.serialize_i64(dt.and_utc().timestamp()) + serializer.serialize_i64(dt.in_utc().timestamp()) } /// Deserialize a `NaiveDateTime` from a seconds timestamp @@ -1028,7 +1028,7 @@ pub mod ts_seconds_option { S: ser::Serializer, { match *opt { - Some(ref dt) => serializer.serialize_some(&dt.and_utc().timestamp()), + Some(ref dt) => serializer.serialize_some(&dt.in_utc().timestamp()), None => serializer.serialize_none(), } } diff --git a/src/naive/datetime/tests.rs b/src/naive/datetime/tests.rs index a0eef36b5b..fc49405427 100644 --- a/src/naive/datetime/tests.rs +++ b/src/naive/datetime/tests.rs @@ -271,7 +271,7 @@ fn test_datetime_add_sub_invariant() { #[test] 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(); + let dt_utc = ndt.in_utc(); assert_eq!(dt_utc.naive_local(), ndt); assert_eq!(dt_utc.timezone(), Utc); @@ -282,9 +282,9 @@ fn test_in_timezone() { } #[test] -fn test_and_utc() { +fn test_in_utc() { let ndt = NaiveDate::from_ymd(2023, 1, 30).unwrap().at_hms(19, 32, 33).unwrap(); - let dt_utc = ndt.and_utc(); + let dt_utc = ndt.in_utc(); assert_eq!(dt_utc.naive_local(), ndt); assert_eq!(dt_utc.timezone(), Utc); } diff --git a/src/naive/time/mod.rs b/src/naive/time/mod.rs index fac4630227..a65b50ad06 100644 --- a/src/naive/time/mod.rs +++ b/src/naive/time/mod.rs @@ -83,7 +83,7 @@ mod tests; /// .unwrap() /// .at_hms_nano(23, 59, 59, 1_000_000_000) /// .unwrap() -/// .and_utc(); +/// .in_utc(); /// # let _ = (t, dt1, dt2); /// ``` /// @@ -167,11 +167,8 @@ mod tests; /// ``` /// use chrono::NaiveDate; /// -/// let dt = NaiveDate::from_ymd(2015, 6, 30) -/// .unwrap() -/// .at_hms_milli(23, 59, 59, 1_000) -/// .unwrap() -/// .and_utc(); +/// let dt = +/// NaiveDate::from_ymd(2015, 6, 30).unwrap().at_hms_milli(23, 59, 59, 1_000).unwrap().in_utc(); /// assert_eq!(format!("{:?}", dt), "2015-06-30T23:59:60Z"); /// ``` /// diff --git a/src/offset/local/mod.rs b/src/offset/local/mod.rs index ec996a4a45..4b209a7f36 100644 --- a/src/offset/local/mod.rs +++ b/src/offset/local/mod.rs @@ -59,7 +59,7 @@ mod inner { use crate::{Datelike, FixedOffset, MappedLocalTime, NaiveDateTime, Timelike}; pub(super) fn offset_from_utc_datetime(utc: NaiveDateTime) -> MappedLocalTime { - let offset = js_sys::Date::from(utc.and_utc()).get_timezone_offset(); + let offset = js_sys::Date::from(utc.in_utc()).get_timezone_offset(); MappedLocalTime::Single(FixedOffset::west((offset as i32) * 60).unwrap()) } diff --git a/src/offset/local/unix.rs b/src/offset/local/unix.rs index dcb07079d7..8298366a60 100644 --- a/src/offset/local/unix.rs +++ b/src/offset/local/unix.rs @@ -151,7 +151,7 @@ impl Cache { if !local { let offset = self .zone - .find_local_time_type(d.and_utc().timestamp()) + .find_local_time_type(d.in_utc().timestamp()) .expect("unable to select local time type") .offset(); @@ -164,7 +164,7 @@ impl Cache { // we pass through the year as the year of a local point in time must either be valid in that locale, or // the entire time was skipped in which case we will return MappedLocalTime::None anyway. self.zone - .find_local_time_type_from_local(d.and_utc().timestamp(), d.year()) + .find_local_time_type_from_local(d.in_utc().timestamp(), d.year()) .expect("unable to select local time type") .and_then(|o| FixedOffset::east(o.offset())) } diff --git a/src/round.rs b/src/round.rs index bf2d896e16..1405a92ef1 100644 --- a/src/round.rs +++ b/src/round.rs @@ -23,7 +23,7 @@ pub trait SubsecRound { /// ``` rust /// # use chrono::{SubsecRound, Timelike, NaiveDate}; /// let dt = - /// NaiveDate::from_ymd(2018, 1, 11).unwrap().at_hms_milli(12, 0, 0, 154).unwrap().and_utc(); + /// NaiveDate::from_ymd(2018, 1, 11).unwrap().at_hms_milli(12, 0, 0, 154).unwrap().in_utc(); /// assert_eq!(dt.round_subsecs(2).nanosecond(), 150_000_000); /// assert_eq!(dt.round_subsecs(1).nanosecond(), 200_000_000); /// ``` @@ -36,7 +36,7 @@ pub trait SubsecRound { /// ``` rust /// # use chrono::{SubsecRound, Timelike, NaiveDate}; /// let dt = - /// NaiveDate::from_ymd(2018, 1, 11).unwrap().at_hms_milli(12, 0, 0, 154).unwrap().and_utc(); + /// NaiveDate::from_ymd(2018, 1, 11).unwrap().at_hms_milli(12, 0, 0, 154).unwrap().in_utc(); /// assert_eq!(dt.trunc_subsecs(2).nanosecond(), 150_000_000); /// assert_eq!(dt.trunc_subsecs(1).nanosecond(), 100_000_000); /// ``` @@ -112,7 +112,7 @@ pub trait DurationRound: Sized { /// ``` rust /// # use chrono::{DurationRound, TimeDelta, NaiveDate}; /// let dt = - /// NaiveDate::from_ymd(2018, 1, 11).unwrap().at_hms_milli(12, 0, 0, 154).unwrap().and_utc(); + /// NaiveDate::from_ymd(2018, 1, 11).unwrap().at_hms_milli(12, 0, 0, 154).unwrap().in_utc(); /// assert_eq!( /// dt.duration_round(TimeDelta::milliseconds(10).unwrap()).unwrap().to_string(), /// "2018-01-11 12:00:00.150 UTC" @@ -130,7 +130,7 @@ pub trait DurationRound: Sized { /// ``` rust /// # use chrono::{DurationRound, TimeDelta, NaiveDate}; /// let dt = - /// NaiveDate::from_ymd(2018, 1, 11).unwrap().at_hms_milli(12, 0, 0, 154).unwrap().and_utc(); + /// NaiveDate::from_ymd(2018, 1, 11).unwrap().at_hms_milli(12, 0, 0, 154).unwrap().in_utc(); /// assert_eq!( /// dt.duration_trunc(TimeDelta::milliseconds(10).unwrap()).unwrap().to_string(), /// "2018-01-11 12:00:00.150 UTC" @@ -180,7 +180,7 @@ where return Err(RoundingError::DurationExceedsLimit); } let stamp = - naive.and_utc().timestamp_nanos().map_err(|_| RoundingError::TimestampExceedsLimit)?; + naive.in_utc().timestamp_nanos().map_err(|_| RoundingError::TimestampExceedsLimit)?; if span == 0 { return Ok(original); } @@ -217,7 +217,7 @@ where return Err(RoundingError::DurationExceedsLimit); } let stamp = - naive.and_utc().timestamp_nanos().map_err(|_| RoundingError::TimestampExceedsLimit)?; + naive.in_utc().timestamp_nanos().map_err(|_| RoundingError::TimestampExceedsLimit)?; let delta_down = stamp % span; match delta_down.cmp(&0) { Ordering::Equal => Ok(original), @@ -247,7 +247,7 @@ pub enum RoundingError { /// .unwrap() /// .at_hms_nano(23, 59, 59, 1_75_500_000) /// .unwrap() - /// .and_utc(); + /// .in_utc(); /// /// assert_eq!( /// dt.duration_round(TimeDelta::days(300 * 365)), diff --git a/tests/wasm.rs b/tests/wasm.rs index 7eea86b633..28e6d6ade6 100644 --- a/tests/wasm.rs +++ b/tests/wasm.rs @@ -22,7 +22,7 @@ fn now() { // Ensure time set by the test script is correct let now = env!("NOW"); - let actual = NaiveDateTime::parse_from_str(&now, "%s").unwrap().and_utc(); + let actual = NaiveDateTime::parse_from_str(&now, "%s").unwrap().in_utc(); let diff = utc - actual; assert!( diff < chrono::TimeDelta::minutes(5),