diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 67a22617db..59c6c9b813 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -125,7 +125,7 @@ impl DateTime { /// (aka "UNIX timestamp"). /// /// The reverse operation of creating a [`DateTime`] from a timestamp can be performed - /// using [`from_timestamp`](DateTime::from_timestamp) or [`TimeZone::timestamp`]. + /// using [`from_timestamp`](DateTime::from_timestamp) or [`TimeZone::and_timestamp`]. /// /// ``` /// use chrono::{DateTime, TimeZone, Utc}; @@ -772,7 +772,7 @@ impl DateTime { /// [`timestamp_subsec_nanos`](DateTime::timestamp_subsec_nanos). /// /// If you need to create a `DateTime` with a [`TimeZone`] different from [`Utc`], use - /// [`TimeZone::timestamp`] or [`DateTime::with_timezone`]. + /// [`TimeZone::and_timestamp`] or [`DateTime::with_timezone`]. /// /// The nanosecond part can exceed 1,000,000,000 in order to represent a /// [leap second](NaiveTime#leap-second-handling), but only when `secs % 60 == 59`. @@ -815,7 +815,7 @@ impl DateTime { /// This is guaranteed to round-trip with [`timestamp_millis`](DateTime::timestamp_millis). /// /// If you need to create a `DateTime` with a [`TimeZone`] different from [`Utc`], use - /// [`TimeZone::timestamp_millis`] or [`DateTime::with_timezone`]. + /// [`TimeZone::and_timestamp_millis`] or [`DateTime::with_timezone`]. /// /// # Errors /// @@ -846,7 +846,7 @@ impl DateTime { /// This is guaranteed to round-trip with [`timestamp_micros`](DateTime::timestamp_micros). /// /// If you need to create a `DateTime` with a [`TimeZone`] different from [`Utc`], use - /// [`TimeZone::timestamp_micros`] or [`DateTime::with_timezone`]. + /// [`TimeZone::and_timestamp_micros`] or [`DateTime::with_timezone`]. /// /// # Errors /// @@ -881,7 +881,7 @@ impl DateTime { /// This is guaranteed to round-trip with [`timestamp_nanos`](DateTime::timestamp_nanos). /// /// If you need to create a `DateTime` with a [`TimeZone`] different from [`Utc`], use - /// [`TimeZone::timestamp_nanos`] or [`DateTime::with_timezone`]. + /// [`TimeZone::and_timestamp_nanos`] or [`DateTime::with_timezone`]. /// /// The UNIX epoch starts on midnight, January 1, 1970, UTC. /// @@ -1744,7 +1744,7 @@ impl TryFrom for DateTime { } } }; - Utc.timestamp(sec, nsec).single().ok_or(OutOfRange::new()) + Utc.and_timestamp(sec, nsec).single().ok_or(OutOfRange::new()) } } @@ -1800,7 +1800,7 @@ impl From for DateTime { ))] impl From<&js_sys::Date> for DateTime { fn from(date: &js_sys::Date) -> DateTime { - Utc.timestamp_millis(date.get_time() as i64).unwrap() + Utc.and_timestamp_millis(date.get_time() as i64).unwrap() } } diff --git a/src/datetime/serde.rs b/src/datetime/serde.rs index 93635d754d..1e6b0d8c38 100644 --- a/src/datetime/serde.rs +++ b/src/datetime/serde.rs @@ -196,10 +196,10 @@ pub mod ts_nanoseconds { /// } /// /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(1526522699, 918355733).unwrap() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(1526522699, 918355733).unwrap() }); /// /// let my_s: S = serde_json::from_str(r#"{ "time": -1 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(-1, 999_999_999).unwrap() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(-1, 999_999_999).unwrap() }); /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> @@ -348,7 +348,7 @@ pub mod ts_nanoseconds_option { /// } /// /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(1526522699, 918355733).single() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(1526522699, 918355733).single() }); /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result>, D::Error> @@ -482,10 +482,10 @@ pub mod ts_microseconds { /// } /// /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(1526522699, 918355000).unwrap() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(1526522699, 918355000).unwrap() }); /// /// let my_s: S = serde_json::from_str(r#"{ "time": -1 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(-1, 999_999_000).unwrap() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(-1, 999_999_000).unwrap() }); /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> @@ -626,7 +626,7 @@ pub mod ts_microseconds_option { /// } /// /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(1526522699, 918355000).single() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(1526522699, 918355000).single() }); /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result>, D::Error> @@ -760,10 +760,10 @@ pub mod ts_milliseconds { /// } /// /// let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(1526522699, 918000000).unwrap() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(1526522699, 918000000).unwrap() }); /// /// let my_s: S = serde_json::from_str(r#"{ "time": -1 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(-1, 999_000_000).unwrap() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(-1, 999_000_000).unwrap() }); /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> @@ -904,7 +904,7 @@ pub mod ts_milliseconds_option { /// } /// /// let my_s: E = serde_json::from_str(r#"{ "time": 1526522699918 }"#)?; - /// assert_eq!(my_s, E::V(S { time: Some(Utc.timestamp(1526522699, 918000000).unwrap()) })); + /// assert_eq!(my_s, E::V(S { time: Some(Utc.and_timestamp(1526522699, 918000000).unwrap()) })); /// let s: E = serde_json::from_str(r#"{ "time": null }"#)?; /// assert_eq!(s, E::V(S { time: None })); /// let t: E = serde_json::from_str(r#"{}"#)?; @@ -1031,7 +1031,7 @@ pub mod ts_seconds { /// } /// /// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(1431684000, 0).unwrap() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(1431684000, 0).unwrap() }); /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result, D::Error> @@ -1152,7 +1152,7 @@ pub mod ts_seconds_option { /// } /// /// let my_s: S = serde_json::from_str(r#"{ "time": 1431684000 }"#)?; - /// assert_eq!(my_s, S { time: Utc.timestamp(1431684000, 0).single() }); + /// assert_eq!(my_s, S { time: Utc.and_timestamp(1431684000, 0).single() }); /// # Ok::<(), serde_json::Error>(()) /// ``` pub fn deserialize<'de, D>(d: D) -> Result>, D::Error> diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index 1ef61a491c..f3a0b406b5 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -1754,7 +1754,7 @@ fn nano_roundrip() { i64::MAX, ] { println!("nanos: {}", nanos); - let dt = Utc.timestamp_nanos(nanos); + let dt = Utc.and_timestamp_nanos(nanos); let nanos2 = dt.timestamp_nanos().expect("value roundtrips"); assert_eq!(nanos, nanos2); } diff --git a/src/offset/local/mod.rs b/src/offset/local/mod.rs index 5c160d00c4..2fa9191dc8 100644 --- a/src/offset/local/mod.rs +++ b/src/offset/local/mod.rs @@ -104,7 +104,7 @@ mod tz_info; /// use chrono::{DateTime, Local, TimeZone}; /// /// let dt1: DateTime = Local::now(); -/// let dt2: DateTime = Local.timestamp(0, 0).unwrap(); +/// let dt2: DateTime = Local.and_timestamp(0, 0).unwrap(); /// assert!(dt1 >= dt2); /// ``` #[derive(Copy, Clone, Debug)] diff --git a/src/offset/mod.rs b/src/offset/mod.rs index 146078e68b..a2d1220161 100644 --- a/src/offset/mod.rs +++ b/src/offset/mod.rs @@ -188,9 +188,9 @@ pub trait TimeZone: Sized + Clone { /// ``` /// use chrono::{TimeZone, Utc}; /// - /// assert_eq!(Utc.timestamp(1431648000, 0).unwrap().to_string(), "2015-05-15 00:00:00 UTC"); + /// assert_eq!(Utc.and_timestamp(1431648000, 0).unwrap().to_string(), "2015-05-15 00:00:00 UTC"); /// ``` - fn timestamp(&self, secs: i64, nsecs: u32) -> MappedLocalTime> { + fn and_timestamp(&self, secs: i64, nsecs: u32) -> MappedLocalTime> { match DateTime::from_timestamp(secs, nsecs) { Ok(dt) => MappedLocalTime::Single(self.from_utc_datetime(&dt.naive_utc())), Err(_) => MappedLocalTime::None, @@ -209,12 +209,12 @@ pub trait TimeZone: Sized + Clone { /// /// ``` /// use chrono::{MappedLocalTime, TimeZone, Utc}; - /// match Utc.timestamp_millis(1431648000) { + /// match Utc.and_timestamp_millis(1431648000) { /// MappedLocalTime::Single(dt) => assert_eq!(dt.timestamp(), 1431648), /// _ => panic!("Incorrect timestamp_millis"), /// }; /// ``` - fn timestamp_millis(&self, millis: i64) -> MappedLocalTime> { + fn and_timestamp_millis(&self, millis: i64) -> MappedLocalTime> { match DateTime::from_timestamp_millis(millis) { Ok(dt) => MappedLocalTime::Single(self.from_utc_datetime(&dt.naive_utc())), Err(_) => MappedLocalTime::None, @@ -224,16 +224,16 @@ pub trait TimeZone: Sized + Clone { /// Makes a new `DateTime` from the number of non-leap nanoseconds /// since January 1, 1970 0:00:00 UTC (aka "UNIX timestamp"). /// - /// Unlike [`timestamp_millis`](#method.timestamp_millis), this never fails. + /// Unlike [`and_timestamp_millis`](#method.and_timestamp_millis), this never fails. /// /// # Example /// /// ``` /// use chrono::{TimeZone, Utc}; /// - /// assert_eq!(Utc.timestamp_nanos(1431648000000000).timestamp(), 1431648); + /// assert_eq!(Utc.and_timestamp_nanos(1431648000000000).timestamp(), 1431648); /// ``` - fn timestamp_nanos(&self, nanos: i64) -> DateTime { + fn and_timestamp_nanos(&self, nanos: i64) -> DateTime { self.from_utc_datetime(&DateTime::from_timestamp_nanos(nanos).naive_utc()) } @@ -245,9 +245,9 @@ pub trait TimeZone: Sized + Clone { /// ``` /// use chrono::{TimeZone, Utc}; /// - /// assert_eq!(Utc.timestamp_micros(1431648000000).unwrap().timestamp(), 1431648); + /// assert_eq!(Utc.and_timestamp_micros(1431648000000).unwrap().timestamp(), 1431648); /// ``` - fn timestamp_micros(&self, micros: i64) -> MappedLocalTime> { + fn and_timestamp_micros(&self, micros: i64) -> MappedLocalTime> { match DateTime::from_timestamp_micros(micros) { Ok(dt) => MappedLocalTime::Single(self.from_utc_datetime(&dt.naive_utc())), Err(_) => MappedLocalTime::None, @@ -326,21 +326,21 @@ mod tests { #[test] fn test_negative_millis() { - let dt = Utc.timestamp_millis(-1000).unwrap(); + let dt = Utc.and_timestamp_millis(-1000).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:59 UTC"); - let dt = Utc.timestamp_millis(-7000).unwrap(); + let dt = Utc.and_timestamp_millis(-7000).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:53 UTC"); - let dt = Utc.timestamp_millis(-7001).unwrap(); + let dt = Utc.and_timestamp_millis(-7001).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:52.999 UTC"); - let dt = Utc.timestamp_millis(-7003).unwrap(); + let dt = Utc.and_timestamp_millis(-7003).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:52.997 UTC"); - let dt = Utc.timestamp_millis(-999).unwrap(); + let dt = Utc.and_timestamp_millis(-999).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:59.001 UTC"); - let dt = Utc.timestamp_millis(-1).unwrap(); + let dt = Utc.and_timestamp_millis(-1).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:59.999 UTC"); - let dt = Utc.timestamp_millis(-60000).unwrap(); + let dt = Utc.and_timestamp_millis(-60000).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:00 UTC"); - let dt = Utc.timestamp_millis(-3600000).unwrap(); + let dt = Utc.and_timestamp_millis(-3600000).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:00:00 UTC"); for (millis, expected) in &[ @@ -348,7 +348,7 @@ mod tests { (-7001, "1969-12-31 23:59:52.999 UTC"), (-7003, "1969-12-31 23:59:52.997 UTC"), ] { - match Utc.timestamp_millis(*millis) { + match Utc.and_timestamp_millis(*millis) { MappedLocalTime::Single(dt) => { assert_eq!(dt.to_string(), *expected); } @@ -359,36 +359,36 @@ mod tests { #[test] fn test_negative_nanos() { - let dt = Utc.timestamp_nanos(-1_000_000_000); + let dt = Utc.and_timestamp_nanos(-1_000_000_000); assert_eq!(dt.to_string(), "1969-12-31 23:59:59 UTC"); - let dt = Utc.timestamp_nanos(-999_999_999); + let dt = Utc.and_timestamp_nanos(-999_999_999); assert_eq!(dt.to_string(), "1969-12-31 23:59:59.000000001 UTC"); - let dt = Utc.timestamp_nanos(-1); + let dt = Utc.and_timestamp_nanos(-1); assert_eq!(dt.to_string(), "1969-12-31 23:59:59.999999999 UTC"); - let dt = Utc.timestamp_nanos(-60_000_000_000); + let dt = Utc.and_timestamp_nanos(-60_000_000_000); assert_eq!(dt.to_string(), "1969-12-31 23:59:00 UTC"); - let dt = Utc.timestamp_nanos(-3_600_000_000_000); + let dt = Utc.and_timestamp_nanos(-3_600_000_000_000); assert_eq!(dt.to_string(), "1969-12-31 23:00:00 UTC"); } #[test] fn test_nanos_never_panics() { - Utc.timestamp_nanos(i64::max_value()); - Utc.timestamp_nanos(i64::default()); - Utc.timestamp_nanos(i64::min_value()); + Utc.and_timestamp_nanos(i64::max_value()); + Utc.and_timestamp_nanos(i64::default()); + Utc.and_timestamp_nanos(i64::min_value()); } #[test] fn test_negative_micros() { - let dt = Utc.timestamp_micros(-1_000_000).unwrap(); + let dt = Utc.and_timestamp_micros(-1_000_000).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:59 UTC"); - let dt = Utc.timestamp_micros(-999_999).unwrap(); + let dt = Utc.and_timestamp_micros(-999_999).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:59.000001 UTC"); - let dt = Utc.timestamp_micros(-1).unwrap(); + let dt = Utc.and_timestamp_micros(-1).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:59.999999 UTC"); - let dt = Utc.timestamp_micros(-60_000_000).unwrap(); + let dt = Utc.and_timestamp_micros(-60_000_000).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:59:00 UTC"); - let dt = Utc.timestamp_micros(-3_600_000_000).unwrap(); + let dt = Utc.and_timestamp_micros(-3_600_000_000).unwrap(); assert_eq!(dt.to_string(), "1969-12-31 23:00:00 UTC"); } } diff --git a/src/offset/utc.rs b/src/offset/utc.rs index 6e3909ece7..8ccc55006a 100644 --- a/src/offset/utc.rs +++ b/src/offset/utc.rs @@ -38,7 +38,7 @@ use crate::OutOfRange; /// /// let dt = DateTime::from_timestamp(61, 0).unwrap(); /// -/// assert_eq!(Utc.timestamp(61, 0).unwrap(), dt); +/// assert_eq!(Utc.and_timestamp(61, 0).unwrap(), dt); /// assert_eq!(Utc.with_ymd_and_hms(1970, 1, 1, 0, 1, 1).unwrap(), dt); /// ``` #[derive(Copy, Clone, PartialEq, Eq, Hash)]