diff --git a/bench/benches/chrono.rs b/bench/benches/chrono.rs index b7b7eb066c..f04c1ae687 100644 --- a/bench/benches/chrono.rs +++ b/bench/benches/chrono.rs @@ -206,7 +206,7 @@ fn bench_naivedate_add_signed(c: &mut Criterion) { } fn bench_datetime_with(c: &mut Criterion) { - let dt = FixedOffset::east(3600).unwrap().with_ymd_and_hms(2023, 9, 23, 7, 36, 0).unwrap(); + let dt = FixedOffset::east(3600).unwrap().and_ymd_and_hms(2023, 9, 23, 7, 36, 0).unwrap(); c.bench_function("bench_datetime_with", |b| { b.iter(|| black_box(black_box(dt).with_hour(12)).unwrap()) }); diff --git a/ci/core-test/src/lib.rs b/ci/core-test/src/lib.rs index 4af7d2ecc5..52eebb503b 100644 --- a/ci/core-test/src/lib.rs +++ b/ci/core-test/src/lib.rs @@ -3,5 +3,5 @@ use chrono::{TimeZone, Utc}; pub fn create_time() { - let _ = Utc.with_ymd_and_hms(2019, 1, 1, 0, 0, 0).unwrap(); + let _ = Utc.and_ymd_and_hms(2019, 1, 1, 0, 0, 0).unwrap(); } diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 044c57cde5..a485281f03 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -102,9 +102,9 @@ impl DateTime { /// ``` /// use chrono::prelude::*; /// - /// let date: DateTime = Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap(); + /// let date: DateTime = Utc.and_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap(); /// let other: DateTime = - /// FixedOffset::east(23).unwrap().with_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap(); + /// FixedOffset::east(23).unwrap().and_ymd_and_hms(2020, 1, 1, 0, 0, 0).unwrap(); /// assert_eq!(date.date_naive(), other.date_naive()); /// ``` #[inline] @@ -130,7 +130,7 @@ impl DateTime { /// ``` /// use chrono::{DateTime, TimeZone, Utc}; /// - /// let dt: DateTime = Utc.with_ymd_and_hms(2015, 5, 15, 0, 0, 0).unwrap(); + /// let dt: DateTime = Utc.and_ymd_and_hms(2015, 5, 15, 0, 0, 0).unwrap(); /// assert_eq!(dt.timestamp(), 1431648000); /// /// assert_eq!(DateTime::from_timestamp(dt.timestamp(), dt.timestamp_subsec_nanos())?, dt); @@ -1044,7 +1044,7 @@ impl DateTime { /// # use chrono::{DateTime, FixedOffset, TimeZone}; /// assert_eq!( /// DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 GMT").unwrap(), - /// FixedOffset::east(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap() + /// FixedOffset::east(0).unwrap().and_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap() /// ); /// ``` pub fn parse_from_rfc2822(s: &str) -> ParseResult> { @@ -1132,7 +1132,7 @@ impl DateTime { /// .unwrap(); /// assert_eq!( /// datetime, - /// FixedOffset::east(2 * 3600).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap() + /// FixedOffset::east(2 * 3600).unwrap().and_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap() /// ); /// assert_eq!(remainder, " trailing text"); /// ``` @@ -1178,7 +1178,7 @@ where /// ```rust /// use chrono::prelude::*; /// - /// let date_time: DateTime = Utc.with_ymd_and_hms(2017, 04, 02, 12, 50, 32).unwrap(); + /// let date_time: DateTime = Utc.and_ymd_and_hms(2017, 04, 02, 12, 50, 32).unwrap(); /// let formatted = format!("{}", date_time.format("%d/%m/%Y %H:%M")); /// assert_eq!(formatted, "02/04/2017 12:50"); /// ``` @@ -1304,11 +1304,11 @@ impl PartialOrd> for DateTime { /// use chrono::prelude::*; /// /// let earlier = Utc - /// .with_ymd_and_hms(2015, 5, 15, 2, 0, 0) + /// .and_ymd_and_hms(2015, 5, 15, 2, 0, 0) /// .unwrap() /// .with_timezone(&FixedOffset::west(1 * 3600).unwrap()); /// let later = Utc - /// .with_ymd_and_hms(2015, 5, 15, 3, 0, 0) + /// .and_ymd_and_hms(2015, 5, 15, 3, 0, 0) /// .unwrap() /// .with_timezone(&FixedOffset::west(5 * 3600).unwrap()); /// @@ -1852,20 +1852,20 @@ where E: ::core::fmt::Debug, { assert_eq!( - to_string_utc(&Utc.with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap()).ok(), + to_string_utc(&Utc.and_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap()).ok(), Some(r#""2014-07-24T12:34:06Z""#.into()) ); assert_eq!( to_string_fixed( - &FixedOffset::east(3660).unwrap().with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap() + &FixedOffset::east(3660).unwrap().and_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap() ) .ok(), Some(r#""2014-07-24T12:34:06+01:01""#.into()) ); assert_eq!( to_string_fixed( - &FixedOffset::east(3650).unwrap().with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap() + &FixedOffset::east(3650).unwrap().and_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap() ) .ok(), // An offset with seconds is not allowed by RFC 3339, so we round it to the nearest minute. @@ -1892,25 +1892,23 @@ fn test_decodable_json( assert_eq!( norm(&utc_from_str(r#""2014-07-24T12:34:06Z""#).ok()), - norm(&Some(Utc.with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap())) + norm(&Some(Utc.and_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap())) ); assert_eq!( norm(&utc_from_str(r#""2014-07-24T13:57:06+01:23""#).ok()), - norm(&Some(Utc.with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap())) + norm(&Some(Utc.and_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap())) ); assert_eq!( norm(&fixed_from_str(r#""2014-07-24T12:34:06Z""#).ok()), - norm(&Some( - FixedOffset::east(0).unwrap().with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap() - )) + norm(&Some(FixedOffset::east(0).unwrap().and_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap())) ); assert_eq!( norm(&fixed_from_str(r#""2014-07-24T13:57:06+01:23""#).ok()), norm(&Some( FixedOffset::east(60 * 60 + 23 * 60) .unwrap() - .with_ymd_and_hms(2014, 7, 24, 13, 57, 6) + .and_ymd_and_hms(2014, 7, 24, 13, 57, 6) .unwrap() )) ); @@ -1919,11 +1917,11 @@ fn test_decodable_json( // the conversion didn't change the instant itself assert_eq!( local_from_str(r#""2014-07-24T12:34:06Z""#).expect("local should parse"), - Utc.with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap() + Utc.and_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap() ); assert_eq!( local_from_str(r#""2014-07-24T13:57:06+01:23""#).expect("local should parse with offset"), - Utc.with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap() + Utc.and_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap() ); assert!(utc_from_str(r#""2014-07-32T12:34:06Z""#).is_err()); diff --git a/src/datetime/serde.rs b/src/datetime/serde.rs index 1e6b0d8c38..59ee9bfbaa 100644 --- a/src/datetime/serde.rs +++ b/src/datetime/serde.rs @@ -970,7 +970,7 @@ pub mod ts_milliseconds_option { /// time: DateTime, /// } /// -/// let time = Utc.with_ymd_and_hms(2015, 5, 15, 10, 0, 0).unwrap(); +/// let time = Utc.and_ymd_and_hms(2015, 5, 15, 10, 0, 0).unwrap(); /// let my_s = S { time: time.clone() }; /// /// let as_string = serde_json::to_string(&my_s)?; @@ -1002,7 +1002,7 @@ pub mod ts_seconds { /// time: DateTime, /// } /// - /// let my_s = S { time: Utc.with_ymd_and_hms(2015, 5, 15, 10, 0, 0).unwrap() }; + /// let my_s = S { time: Utc.and_ymd_and_hms(2015, 5, 15, 10, 0, 0).unwrap() }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1431684000}"#); /// # Ok::<(), serde_json::Error>(()) @@ -1088,7 +1088,7 @@ pub mod ts_seconds { /// time: Option>, /// } /// -/// let time = Some(Utc.with_ymd_and_hms(2015, 5, 15, 10, 0, 0).unwrap()); +/// let time = Some(Utc.and_ymd_and_hms(2015, 5, 15, 10, 0, 0).unwrap()); /// let my_s = S { time: time.clone() }; /// /// let as_string = serde_json::to_string(&my_s)?; @@ -1120,7 +1120,7 @@ pub mod ts_seconds_option { /// time: Option>, /// } /// - /// let my_s = S { time: Some(Utc.with_ymd_and_hms(2015, 5, 15, 10, 0, 0).unwrap()) }; + /// let my_s = S { time: Some(Utc.and_ymd_and_hms(2015, 5, 15, 10, 0, 0).unwrap()) }; /// let as_string = serde_json::to_string(&my_s)?; /// assert_eq!(as_string, r#"{"time":1431684000}"#); /// # Ok::<(), serde_json::Error>(()) @@ -1226,7 +1226,7 @@ mod tests { // it is not self-describing. use bincode::{deserialize, serialize}; - let dt = Utc.with_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap(); + let dt = Utc.and_ymd_and_hms(2014, 7, 24, 12, 34, 6).unwrap(); let encoded = serialize(&dt).unwrap(); let decoded: DateTime = deserialize(&encoded).unwrap(); assert_eq!(dt, decoded); @@ -1269,7 +1269,7 @@ mod tests { let tz = TestTimeZone; assert_eq!(format!("{:?}", &tz), "TEST"); - let dt = tz.with_ymd_and_hms(2023, 4, 24, 21, 10, 33).unwrap(); + let dt = tz.and_ymd_and_hms(2023, 4, 24, 21, 10, 33).unwrap(); let encoded = serde_json::to_string(&dt).unwrap(); dbg!(&encoded); let decoded: DateTime = serde_json::from_str(&encoded).unwrap(); diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index f3a0b406b5..691c354d09 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -306,38 +306,38 @@ fn test_datetime_add_days() { let kst = FixedOffset::east(9 * 60 * 60).unwrap(); assert_eq!( - format!("{}", est.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Days::new(5)), + format!("{}", est.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Days::new(5)), "2014-05-11 07:08:09 -05:00" ); assert_eq!( - format!("{}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Days::new(5)), + format!("{}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Days::new(5)), "2014-05-11 07:08:09 +09:00" ); assert_eq!( - format!("{}", est.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Days::new(35)), + format!("{}", est.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Days::new(35)), "2014-06-10 07:08:09 -05:00" ); assert_eq!( - format!("{}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Days::new(35)), + format!("{}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Days::new(35)), "2014-06-10 07:08:09 +09:00" ); assert_eq!( - format!("{}", DstTester.with_ymd_and_hms(2014, 4, 6, 7, 8, 9).unwrap() + Days::new(5)), + format!("{}", DstTester.and_ymd_and_hms(2014, 4, 6, 7, 8, 9).unwrap() + Days::new(5)), "2014-04-11 07:08:09 +09:00" ); assert_eq!( - format!("{}", DstTester.with_ymd_and_hms(2014, 4, 6, 7, 8, 9).unwrap() + Days::new(10)), + format!("{}", DstTester.and_ymd_and_hms(2014, 4, 6, 7, 8, 9).unwrap() + Days::new(10)), "2014-04-16 07:08:09 +08:00" ); assert_eq!( - format!("{}", DstTester.with_ymd_and_hms(2014, 9, 6, 7, 8, 9).unwrap() + Days::new(5)), + format!("{}", DstTester.and_ymd_and_hms(2014, 9, 6, 7, 8, 9).unwrap() + Days::new(5)), "2014-09-11 07:08:09 +08:00" ); assert_eq!( - format!("{}", DstTester.with_ymd_and_hms(2014, 9, 6, 7, 8, 9).unwrap() + Days::new(10)), + format!("{}", DstTester.and_ymd_and_hms(2014, 9, 6, 7, 8, 9).unwrap() + Days::new(10)), "2014-09-16 07:08:09 +09:00" ); } @@ -348,20 +348,20 @@ fn test_datetime_sub_days() { let kst = FixedOffset::east(9 * 60 * 60).unwrap(); assert_eq!( - format!("{}", est.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Days::new(5)), + format!("{}", est.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Days::new(5)), "2014-05-01 07:08:09 -05:00" ); assert_eq!( - format!("{}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Days::new(5)), + format!("{}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Days::new(5)), "2014-05-01 07:08:09 +09:00" ); assert_eq!( - format!("{}", est.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Days::new(35)), + format!("{}", est.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Days::new(35)), "2014-04-01 07:08:09 -05:00" ); assert_eq!( - format!("{}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Days::new(35)), + format!("{}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Days::new(35)), "2014-04-01 07:08:09 +09:00" ); } @@ -372,20 +372,20 @@ fn test_datetime_add_months() { let kst = FixedOffset::east(9 * 60 * 60).unwrap(); assert_eq!( - format!("{}", est.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Months::new(1)), + format!("{}", est.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Months::new(1)), "2014-06-06 07:08:09 -05:00" ); assert_eq!( - format!("{}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Months::new(1)), + format!("{}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Months::new(1)), "2014-06-06 07:08:09 +09:00" ); assert_eq!( - format!("{}", est.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Months::new(5)), + format!("{}", est.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Months::new(5)), "2014-10-06 07:08:09 -05:00" ); assert_eq!( - format!("{}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Months::new(5)), + format!("{}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() + Months::new(5)), "2014-10-06 07:08:09 +09:00" ); } @@ -396,20 +396,20 @@ fn test_datetime_sub_months() { let kst = FixedOffset::east(9 * 60 * 60).unwrap(); assert_eq!( - format!("{}", est.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Months::new(1)), + format!("{}", est.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Months::new(1)), "2014-04-06 07:08:09 -05:00" ); assert_eq!( - format!("{}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Months::new(1)), + format!("{}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Months::new(1)), "2014-04-06 07:08:09 +09:00" ); assert_eq!( - format!("{}", est.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Months::new(5)), + format!("{}", est.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Months::new(5)), "2013-12-06 07:08:09 -05:00" ); assert_eq!( - format!("{}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Months::new(5)), + format!("{}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap() - Months::new(5)), "2013-12-06 07:08:09 +09:00" ); } @@ -425,7 +425,7 @@ fn ymdhms( min: u32, sec: u32, ) -> DateTime { - fixedoffset.with_ymd_and_hms(year, month, day, hour, min, sec).unwrap() + fixedoffset.and_ymd_and_hms(year, month, day, hour, min, sec).unwrap() } // local helper function to easily create a DateTime @@ -441,7 +441,7 @@ fn ymdhms_milli( milli: u32, ) -> DateTime { fixedoffset - .with_ymd_and_hms(year, month, day, hour, min, sec) + .and_ymd_and_hms(year, month, day, hour, min, sec) .unwrap() .with_nanosecond(milli * 1_000_000) .unwrap() @@ -461,7 +461,7 @@ fn ymdhms_micro( micro: u32, ) -> DateTime { fixedoffset - .with_ymd_and_hms(year, month, day, hour, min, sec) + .and_ymd_and_hms(year, month, day, hour, min, sec) .unwrap() .with_nanosecond(micro * 1000) .unwrap() @@ -481,7 +481,7 @@ fn ymdhms_nano( nano: u32, ) -> DateTime { fixedoffset - .with_ymd_and_hms(year, month, day, hour, min, sec) + .and_ymd_and_hms(year, month, day, hour, min, sec) .unwrap() .with_nanosecond(nano) .unwrap() @@ -490,7 +490,7 @@ fn ymdhms_nano( // local helper function to easily create a DateTime #[cfg(feature = "alloc")] fn ymdhms_utc(year: i32, month: u32, day: u32, hour: u32, min: u32, sec: u32) -> DateTime { - Utc.with_ymd_and_hms(year, month, day, hour, min, sec).unwrap() + Utc.and_ymd_and_hms(year, month, day, hour, min, sec).unwrap() } // local helper function to easily create a DateTime @@ -503,7 +503,7 @@ fn ymdhms_milli_utc( sec: u32, milli: u32, ) -> DateTime { - Utc.with_ymd_and_hms(year, month, day, hour, min, sec) + Utc.and_ymd_and_hms(year, month, day, hour, min, sec) .unwrap() .with_nanosecond(milli * 1_000_000) .unwrap() @@ -516,77 +516,77 @@ fn test_datetime_offset() { let kst = FixedOffset::east(9 * 60 * 60).unwrap(); assert_eq!( - format!("{}", Utc.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), + format!("{}", Utc.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), "2014-05-06 07:08:09 UTC" ); assert_eq!( - format!("{}", edt.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), + format!("{}", edt.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), "2014-05-06 07:08:09 -04:00" ); assert_eq!( - format!("{}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), + format!("{}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), "2014-05-06 07:08:09 +09:00" ); assert_eq!( - format!("{:?}", Utc.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), + format!("{:?}", Utc.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), "2014-05-06T07:08:09Z" ); assert_eq!( - format!("{:?}", edt.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), + format!("{:?}", edt.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), "2014-05-06T07:08:09-04:00" ); assert_eq!( - format!("{:?}", kst.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), + format!("{:?}", kst.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap()), "2014-05-06T07:08:09+09:00" ); // edge cases assert_eq!( - format!("{:?}", Utc.with_ymd_and_hms(2014, 5, 6, 0, 0, 0).unwrap()), + format!("{:?}", Utc.and_ymd_and_hms(2014, 5, 6, 0, 0, 0).unwrap()), "2014-05-06T00:00:00Z" ); assert_eq!( - format!("{:?}", edt.with_ymd_and_hms(2014, 5, 6, 0, 0, 0).unwrap()), + format!("{:?}", edt.and_ymd_and_hms(2014, 5, 6, 0, 0, 0).unwrap()), "2014-05-06T00:00:00-04:00" ); assert_eq!( - format!("{:?}", kst.with_ymd_and_hms(2014, 5, 6, 0, 0, 0).unwrap()), + format!("{:?}", kst.and_ymd_and_hms(2014, 5, 6, 0, 0, 0).unwrap()), "2014-05-06T00:00:00+09:00" ); assert_eq!( - format!("{:?}", Utc.with_ymd_and_hms(2014, 5, 6, 23, 59, 59).unwrap()), + format!("{:?}", Utc.and_ymd_and_hms(2014, 5, 6, 23, 59, 59).unwrap()), "2014-05-06T23:59:59Z" ); assert_eq!( - format!("{:?}", edt.with_ymd_and_hms(2014, 5, 6, 23, 59, 59).unwrap()), + format!("{:?}", edt.and_ymd_and_hms(2014, 5, 6, 23, 59, 59).unwrap()), "2014-05-06T23:59:59-04:00" ); assert_eq!( - format!("{:?}", kst.with_ymd_and_hms(2014, 5, 6, 23, 59, 59).unwrap()), + format!("{:?}", kst.and_ymd_and_hms(2014, 5, 6, 23, 59, 59).unwrap()), "2014-05-06T23:59:59+09:00" ); - let dt = Utc.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap(); - assert_eq!(dt, edt.with_ymd_and_hms(2014, 5, 6, 3, 8, 9).unwrap()); + let dt = Utc.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap(); + assert_eq!(dt, edt.and_ymd_and_hms(2014, 5, 6, 3, 8, 9).unwrap()); assert_eq!( dt + TimeDelta::seconds(3600 + 60 + 1), - Utc.with_ymd_and_hms(2014, 5, 6, 8, 9, 10).unwrap() + Utc.and_ymd_and_hms(2014, 5, 6, 8, 9, 10).unwrap() ); assert_eq!( - dt.signed_duration_since(edt.with_ymd_and_hms(2014, 5, 6, 10, 11, 12).unwrap()), + dt.signed_duration_since(edt.and_ymd_and_hms(2014, 5, 6, 10, 11, 12).unwrap()), TimeDelta::seconds(-7 * 3600 - 3 * 60 - 3) ); - assert_eq!(*Utc.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap().offset(), Utc); - assert_eq!(*edt.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap().offset(), edt); - assert!(*edt.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap().offset() != est); + assert_eq!(*Utc.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap().offset(), Utc); + assert_eq!(*edt.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap().offset(), edt); + assert!(*edt.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap().offset() != est); } #[test] #[allow(clippy::needless_borrow, clippy::op_ref)] fn signed_duration_since_autoref() { - let dt1 = Utc.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap(); - let dt2 = Utc.with_ymd_and_hms(2014, 3, 4, 5, 6, 7).unwrap(); + let dt1 = Utc.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap(); + let dt2 = Utc.and_ymd_and_hms(2014, 3, 4, 5, 6, 7).unwrap(); let diff1 = dt1.signed_duration_since(dt2); // Copy/consume #[allow(clippy::needless_borrows_for_generic_args)] let diff2 = dt2.signed_duration_since(&dt1); // Take by reference @@ -600,21 +600,21 @@ fn signed_duration_since_autoref() { #[test] fn test_datetime_date_and_time() { let tz = FixedOffset::east(5 * 60 * 60).unwrap(); - let d = tz.with_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap(); + let d = tz.and_ymd_and_hms(2014, 5, 6, 7, 8, 9).unwrap(); assert_eq!(d.time(), NaiveTime::from_hms(7, 8, 9).unwrap()); assert_eq!(d.date_naive(), NaiveDate::from_ymd(2014, 5, 6).unwrap()); let tz = FixedOffset::east(4 * 60 * 60).unwrap(); - let d = tz.with_ymd_and_hms(2016, 5, 4, 3, 2, 1).unwrap(); + let d = tz.and_ymd_and_hms(2016, 5, 4, 3, 2, 1).unwrap(); assert_eq!(d.time(), NaiveTime::from_hms(3, 2, 1).unwrap()); assert_eq!(d.date_naive(), NaiveDate::from_ymd(2016, 5, 4).unwrap()); let tz = FixedOffset::west(13 * 60 * 60).unwrap(); - let d = tz.with_ymd_and_hms(2017, 8, 9, 12, 34, 56).unwrap(); + let d = tz.and_ymd_and_hms(2017, 8, 9, 12, 34, 56).unwrap(); assert_eq!(d.time(), NaiveTime::from_hms(12, 34, 56).unwrap()); assert_eq!(d.date_naive(), NaiveDate::from_ymd(2017, 8, 9).unwrap()); - let utc_d = Utc.with_ymd_and_hms(2017, 8, 9, 12, 34, 56).unwrap(); + let utc_d = Utc.and_ymd_and_hms(2017, 8, 9, 12, 34, 56).unwrap(); assert!(utc_d < d); } @@ -634,11 +634,11 @@ fn test_datetime_rfc2822() { // timezone 0 assert_eq!( - Utc.with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap().to_rfc2822(), + Utc.and_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap().to_rfc2822(), "Wed, 18 Feb 2015 23:16:09 +0000" ); assert_eq!( - Utc.with_ymd_and_hms(2015, 2, 1, 23, 16, 9).unwrap().to_rfc2822(), + Utc.and_ymd_and_hms(2015, 2, 1, 23, 16, 9).unwrap().to_rfc2822(), "Sun, 1 Feb 2015 23:16:09 +0000" ); // timezone +05 @@ -688,11 +688,11 @@ fn test_datetime_rfc2822() { assert_eq!( DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 +0000"), - Ok(FixedOffset::east(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()) + Ok(FixedOffset::east(0).unwrap().and_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()) ); assert_eq!( DateTime::parse_from_rfc2822("Wed, 18 Feb 2015 23:16:09 -0000"), - Ok(FixedOffset::east(0).unwrap().with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()) + Ok(FixedOffset::east(0).unwrap().and_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap()) ); assert_eq!( ymdhms_micro(&edt, 2015, 2, 18, 23, 59, 59, 1_234_567).to_rfc2822(), @@ -756,7 +756,7 @@ fn test_datetime_rfc3339() { // timezone 0 assert_eq!( - Utc.with_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap().to_rfc3339(), + Utc.and_ymd_and_hms(2015, 2, 18, 23, 16, 9).unwrap().to_rfc3339(), "2015-02-18T23:16:09+00:00" ); // timezone +05 @@ -1233,7 +1233,7 @@ fn test_datetime_parse_from_str() { #[test] fn test_to_string_round_trip() { - let dt = Utc.with_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap(); + let dt = Utc.and_ymd_and_hms(2000, 1, 1, 0, 0, 0).unwrap(); let _dt: DateTime = dt.to_string().parse().unwrap(); let ndt_fixed = dt.with_timezone(&FixedOffset::east(3600).unwrap()); @@ -1288,7 +1288,7 @@ fn test_from_system_time() { let nanos = 999_999_000; - let epoch = Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(); + let epoch = Utc.and_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap(); // SystemTime -> DateTime assert_eq!(DateTime::::try_from(UNIX_EPOCH).unwrap(), epoch); @@ -1633,12 +1633,12 @@ fn test_datetime_sub_assign_local() { fn test_core_duration_ops() { use core::time::Duration; - let mut utc_dt = Utc.with_ymd_and_hms(2023, 8, 29, 11, 34, 12).unwrap(); + let mut utc_dt = Utc.and_ymd_and_hms(2023, 8, 29, 11, 34, 12).unwrap(); let same = utc_dt + Duration::ZERO; assert_eq!(utc_dt, same); utc_dt += Duration::new(3600, 0); - assert_eq!(utc_dt, Utc.with_ymd_and_hms(2023, 8, 29, 12, 34, 12).unwrap()); + assert_eq!(utc_dt, Utc.and_ymd_and_hms(2023, 8, 29, 12, 34, 12).unwrap()); } #[test] @@ -1646,7 +1646,7 @@ fn test_core_duration_ops() { fn test_core_duration_max() { use core::time::Duration; - let mut utc_dt = Utc.with_ymd_and_hms(2023, 8, 29, 11, 34, 12).unwrap(); + let mut utc_dt = Utc.and_ymd_and_hms(2023, 8, 29, 11, 34, 12).unwrap(); utc_dt += Duration::MAX; } @@ -1678,33 +1678,33 @@ fn test_datetime_fixed_offset() { #[test] fn test_datetime_to_utc() { - let dt = FixedOffset::east(3600).unwrap().with_ymd_and_hms(2020, 2, 22, 23, 24, 25).unwrap(); + let dt = FixedOffset::east(3600).unwrap().and_ymd_and_hms(2020, 2, 22, 23, 24, 25).unwrap(); let dt_utc: DateTime = dt.to_utc(); assert_eq!(dt, dt_utc); } #[test] fn test_add_sub_months() { - let utc_dt = Utc.with_ymd_and_hms(2018, 9, 5, 23, 58, 0).unwrap(); - assert_eq!(utc_dt + Months::new(15), Utc.with_ymd_and_hms(2019, 12, 5, 23, 58, 0).unwrap()); + let utc_dt = Utc.and_ymd_and_hms(2018, 9, 5, 23, 58, 0).unwrap(); + assert_eq!(utc_dt + Months::new(15), Utc.and_ymd_and_hms(2019, 12, 5, 23, 58, 0).unwrap()); - let utc_dt = Utc.with_ymd_and_hms(2020, 1, 31, 23, 58, 0).unwrap(); - assert_eq!(utc_dt + Months::new(1), Utc.with_ymd_and_hms(2020, 2, 29, 23, 58, 0).unwrap()); - assert_eq!(utc_dt + Months::new(2), Utc.with_ymd_and_hms(2020, 3, 31, 23, 58, 0).unwrap()); + let utc_dt = Utc.and_ymd_and_hms(2020, 1, 31, 23, 58, 0).unwrap(); + assert_eq!(utc_dt + Months::new(1), Utc.and_ymd_and_hms(2020, 2, 29, 23, 58, 0).unwrap()); + assert_eq!(utc_dt + Months::new(2), Utc.and_ymd_and_hms(2020, 3, 31, 23, 58, 0).unwrap()); - let utc_dt = Utc.with_ymd_and_hms(2018, 9, 5, 23, 58, 0).unwrap(); - assert_eq!(utc_dt - Months::new(15), Utc.with_ymd_and_hms(2017, 6, 5, 23, 58, 0).unwrap()); + let utc_dt = Utc.and_ymd_and_hms(2018, 9, 5, 23, 58, 0).unwrap(); + assert_eq!(utc_dt - Months::new(15), Utc.and_ymd_and_hms(2017, 6, 5, 23, 58, 0).unwrap()); - let utc_dt = Utc.with_ymd_and_hms(2020, 3, 31, 23, 58, 0).unwrap(); - assert_eq!(utc_dt - Months::new(1), Utc.with_ymd_and_hms(2020, 2, 29, 23, 58, 0).unwrap()); - assert_eq!(utc_dt - Months::new(2), Utc.with_ymd_and_hms(2020, 1, 31, 23, 58, 0).unwrap()); + let utc_dt = Utc.and_ymd_and_hms(2020, 3, 31, 23, 58, 0).unwrap(); + assert_eq!(utc_dt - Months::new(1), Utc.and_ymd_and_hms(2020, 2, 29, 23, 58, 0).unwrap()); + assert_eq!(utc_dt - Months::new(2), Utc.and_ymd_and_hms(2020, 1, 31, 23, 58, 0).unwrap()); } #[test] fn test_auto_conversion() { - let utc_dt = Utc.with_ymd_and_hms(2018, 9, 5, 23, 58, 0).unwrap(); + let utc_dt = Utc.and_ymd_and_hms(2018, 9, 5, 23, 58, 0).unwrap(); let cdt_dt = - FixedOffset::west(5 * 60 * 60).unwrap().with_ymd_and_hms(2018, 9, 5, 18, 58, 0).unwrap(); + FixedOffset::west(5 * 60 * 60).unwrap().and_ymd_and_hms(2018, 9, 5, 18, 58, 0).unwrap(); let utc_dt2: DateTime = cdt_dt.into(); assert_eq!(utc_dt, utc_dt2); } @@ -1714,7 +1714,7 @@ fn test_auto_conversion() { fn locale_decimal_point() { use crate::Locale::{ar_SY, nl_NL}; let dt = - Utc.with_ymd_and_hms(2018, 9, 5, 18, 58, 0).unwrap().with_nanosecond(123456780).unwrap(); + Utc.and_ymd_and_hms(2018, 9, 5, 18, 58, 0).unwrap().with_nanosecond(123456780).unwrap(); assert_eq!(dt.format_localized("%T%.f", nl_NL).to_string(), "18:58:00,123456780"); assert_eq!(dt.format_localized("%T%.3f", nl_NL).to_string(), "18:58:00,123"); diff --git a/src/format/formatting.rs b/src/format/formatting.rs index 54fda69ee5..a11b2beb6a 100644 --- a/src/format/formatting.rs +++ b/src/format/formatting.rs @@ -700,7 +700,7 @@ mod tests { #[cfg(feature = "alloc")] fn test_datetime_format_alignment() { let datetime = Utc - .with_ymd_and_hms(2007, 1, 2, 12, 34, 56) + .and_ymd_and_hms(2007, 1, 2, 12, 34, 56) .unwrap() .with_nanosecond(123456789) .unwrap(); diff --git a/src/format/mod.rs b/src/format/mod.rs index d145356229..69de0a74e6 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -20,7 +20,7 @@ #![cfg_attr(feature = "std", doc = "```rust")] //! use chrono::{NaiveDateTime, TimeZone, Utc}; //! -//! let date_time = Utc.with_ymd_and_hms(2020, 11, 10, 0, 1, 32).unwrap(); +//! let date_time = Utc.and_ymd_and_hms(2020, 11, 10, 0, 1, 32).unwrap(); //! //! let formatted = format!("{}", date_time.format("%Y-%m-%d %H:%M:%S")); //! assert_eq!(formatted, "2020-11-10 00:01:32"); diff --git a/src/format/parse.rs b/src/format/parse.rs index 1667a27407..e5ad1ef33c 100644 --- a/src/format/parse.rs +++ b/src/format/parse.rs @@ -1587,7 +1587,7 @@ mod tests { let ymd_hmsn = |y, m, d, h, n, s, nano, off| { FixedOffset::east(off * 60 * 60) .unwrap() - .with_ymd_and_hms(y, m, d, h, n, s) + .and_ymd_and_hms(y, m, d, h, n, s) .unwrap() .with_nanosecond(nano) .unwrap() @@ -1681,7 +1681,7 @@ mod tests { fn parse_rfc850() { static RFC850_FMT: &str = "%A, %d-%b-%y %T GMT"; - let dt = Utc.with_ymd_and_hms(1994, 11, 6, 8, 49, 37).unwrap(); + let dt = Utc.and_ymd_and_hms(1994, 11, 6, 8, 49, 37).unwrap(); // Check that the format is what we expect #[cfg(feature = "alloc")] @@ -1697,27 +1697,27 @@ mod tests { // Sunday parsed incorrectly). let testdates = [ ( - Utc.with_ymd_and_hms(1994, 11, 7, 8, 49, 37).unwrap(), + Utc.and_ymd_and_hms(1994, 11, 7, 8, 49, 37).unwrap(), "Monday, 07-Nov-94 08:49:37 GMT", ), ( - Utc.with_ymd_and_hms(1994, 11, 8, 8, 49, 37).unwrap(), + Utc.and_ymd_and_hms(1994, 11, 8, 8, 49, 37).unwrap(), "Tuesday, 08-Nov-94 08:49:37 GMT", ), ( - Utc.with_ymd_and_hms(1994, 11, 9, 8, 49, 37).unwrap(), + Utc.and_ymd_and_hms(1994, 11, 9, 8, 49, 37).unwrap(), "Wednesday, 09-Nov-94 08:49:37 GMT", ), ( - Utc.with_ymd_and_hms(1994, 11, 10, 8, 49, 37).unwrap(), + Utc.and_ymd_and_hms(1994, 11, 10, 8, 49, 37).unwrap(), "Thursday, 10-Nov-94 08:49:37 GMT", ), ( - Utc.with_ymd_and_hms(1994, 11, 11, 8, 49, 37).unwrap(), + Utc.and_ymd_and_hms(1994, 11, 11, 8, 49, 37).unwrap(), "Friday, 11-Nov-94 08:49:37 GMT", ), ( - Utc.with_ymd_and_hms(1994, 11, 12, 8, 49, 37).unwrap(), + Utc.and_ymd_and_hms(1994, 11, 12, 8, 49, 37).unwrap(), "Saturday, 12-Nov-94 08:49:37 GMT", ), ]; @@ -1751,7 +1751,7 @@ mod tests { let ymd_hmsn = |y, m, d, h, n, s, nano, off| { FixedOffset::east(off * 60 * 60) .unwrap() - .with_ymd_and_hms(y, m, d, h, n, s) + .and_ymd_and_hms(y, m, d, h, n, s) .unwrap() .with_nanosecond(nano) .unwrap() diff --git a/src/format/parsed.rs b/src/format/parsed.rs index 7af32f24d1..a1dc8a0e78 100644 --- a/src/format/parsed.rs +++ b/src/format/parsed.rs @@ -1741,7 +1741,7 @@ mod tests { // single result from timestamp assert_eq!( parse!(Utc; timestamp: 1_420_000_000, offset: 0), - Ok(Utc.with_ymd_and_hms(2014, 12, 31, 4, 26, 40).unwrap()) + Ok(Utc.and_ymd_and_hms(2014, 12, 31, 4, 26, 40).unwrap()) ); assert_eq!(parse!(Utc; timestamp: 1_420_000_000, offset: 32400), Err(IMPOSSIBLE)); assert_eq!( @@ -1752,7 +1752,7 @@ mod tests { parse!(FixedOffset::east(32400).unwrap(); timestamp: 1_420_000_000, offset: 32400), Ok(FixedOffset::east(32400) .unwrap() - .with_ymd_and_hms(2014, 12, 31, 13, 26, 40) + .and_ymd_and_hms(2014, 12, 31, 13, 26, 40) .unwrap()) ); diff --git a/src/format/strftime.rs b/src/format/strftime.rs index d928c7bac6..0b7124cc5a 100644 --- a/src/format/strftime.rs +++ b/src/format/strftime.rs @@ -266,7 +266,7 @@ impl<'a> StrftimeItems<'a> { /// /// let dt = FixedOffset::east(9 * 60 * 60) /// .unwrap() - /// .with_ymd_and_hms(2023, 7, 11, 0, 34, 59) + /// .and_ymd_and_hms(2023, 7, 11, 0, 34, 59) /// .unwrap(); /// /// // Note: you usually want to combine `StrftimeItems::new_with_locale` with other @@ -963,7 +963,7 @@ mod tests { fn test_strftime_docs_localized() { let dt = FixedOffset::east(34200) .unwrap() - .with_ymd_and_hms(2001, 7, 8, 0, 34, 59) + .and_ymd_and_hms(2001, 7, 8, 0, 34, 59) .unwrap() .with_nanosecond(1_026_490_708) .unwrap(); @@ -1037,7 +1037,7 @@ mod tests { fn test_strftime_localized_korean() { let dt = FixedOffset::east(34200) .unwrap() - .with_ymd_and_hms(2001, 7, 8, 0, 34, 59) + .and_ymd_and_hms(2001, 7, 8, 0, 34, 59) .unwrap() .with_nanosecond(1_026_490_708) .unwrap(); @@ -1066,7 +1066,7 @@ mod tests { fn test_strftime_localized_japanese() { let dt = FixedOffset::east(34200) .unwrap() - .with_ymd_and_hms(2001, 7, 8, 0, 34, 59) + .and_ymd_and_hms(2001, 7, 8, 0, 34, 59) .unwrap() .with_nanosecond(1_026_490_708) .unwrap(); @@ -1093,8 +1093,8 @@ mod tests { #[test] #[cfg(all(feature = "unstable-locales", feature = "alloc"))] fn test_strftime_localized_time() { - let dt1 = Utc.with_ymd_and_hms(2024, 2, 9, 6, 54, 32).unwrap(); - let dt2 = Utc.with_ymd_and_hms(2024, 2, 9, 18, 54, 32).unwrap(); + let dt1 = Utc.and_ymd_and_hms(2024, 2, 9, 6, 54, 32).unwrap(); + let dt2 = Utc.and_ymd_and_hms(2024, 2, 9, 18, 54, 32).unwrap(); // Some of these locales gave issues before pure-rust-locales 0.8.0 with chrono 0.4.27+ assert_eq!(dt1.format_localized("%X", Locale::nl_NL).to_string(), "06:54:32"); assert_eq!(dt2.format_localized("%X", Locale::nl_NL).to_string(), "18:54:32"); @@ -1129,7 +1129,7 @@ mod tests { fn test_strftime_parse() { let fmt_str = StrftimeItems::new("%Y-%m-%dT%H:%M:%S%z"); let fmt_items = fmt_str.parse().unwrap(); - let dt = Utc.with_ymd_and_hms(2014, 5, 7, 12, 34, 56).unwrap(); + let dt = Utc.and_ymd_and_hms(2014, 5, 7, 12, 34, 56).unwrap(); assert_eq!(&dt.format_with_items(fmt_items.iter()).to_string(), "2014-05-07T12:34:56+0000"); } } diff --git a/src/lib.rs b/src/lib.rs index ddc02da8b1..b8582f17f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,7 +134,7 @@ //! //! # fn doctest() -> Option<()> { //! -//! let dt = Utc.with_ymd_and_hms(2014, 7, 8, 9, 10, 11).unwrap(); // `2014-07-08T09:10:11Z` +//! let dt = Utc.and_ymd_and_hms(2014, 7, 8, 9, 10, 11).unwrap(); // `2014-07-08T09:10:11Z` //! assert_eq!(dt, NaiveDate::from_ymd(2014, 7, 8).unwrap().and_hms(9, 10, 11).unwrap().and_local_timezone(Utc).unwrap()); //! //! // July 8 is 188th day of the year 2014 (`o` for "ordinal") @@ -148,13 +148,13 @@ //! //! // dynamic verification //! assert_eq!( -//! Utc.with_ymd_and_hms(2014, 7, 8, 21, 15, 33), +//! Utc.and_ymd_and_hms(2014, 7, 8, 21, 15, 33), //! MappedLocalTime::Single( //! NaiveDate::from_ymd(2014, 7, 8).unwrap().and_hms(21, 15, 33).unwrap().and_utc() //! ) //! ); -//! assert_eq!(Utc.with_ymd_and_hms(2014, 7, 8, 80, 15, 33), MappedLocalTime::None); -//! assert_eq!(Utc.with_ymd_and_hms(2014, 7, 38, 21, 15, 33), MappedLocalTime::None); +//! assert_eq!(Utc.and_ymd_and_hms(2014, 7, 8, 80, 15, 33), MappedLocalTime::None); +//! assert_eq!(Utc.and_ymd_and_hms(2014, 7, 38, 21, 15, 33), MappedLocalTime::None); //! //! # #[cfg(feature = "clock")] { //! // other time zone objects can be used to construct a local datetime. @@ -201,14 +201,14 @@ //! assert_eq!(dt.with_year(-300).unwrap().num_days_from_ce(), -109606); // November 29, 301 BCE //! //! // arithmetic operations -//! let dt1 = Utc.with_ymd_and_hms(2014, 11, 14, 8, 9, 10).unwrap(); -//! let dt2 = Utc.with_ymd_and_hms(2014, 11, 14, 10, 9, 8).unwrap(); +//! let dt1 = Utc.and_ymd_and_hms(2014, 11, 14, 8, 9, 10).unwrap(); +//! let dt2 = Utc.and_ymd_and_hms(2014, 11, 14, 10, 9, 8).unwrap(); //! assert_eq!(dt1.signed_duration_since(dt2), TimeDelta::seconds(-2 * 3600 + 2)); //! assert_eq!(dt2.signed_duration_since(dt1), TimeDelta::seconds(2 * 3600 - 2)); -//! assert_eq!(Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap() + TimeDelta::seconds(1_000_000_000), -//! Utc.with_ymd_and_hms(2001, 9, 9, 1, 46, 40).unwrap()); -//! assert_eq!(Utc.with_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap() - TimeDelta::seconds(1_000_000_000), -//! Utc.with_ymd_and_hms(1938, 4, 24, 22, 13, 20).unwrap()); +//! assert_eq!(Utc.and_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap() + TimeDelta::seconds(1_000_000_000), +//! Utc.and_ymd_and_hms(2001, 9, 9, 1, 46, 40).unwrap()); +//! assert_eq!(Utc.and_ymd_and_hms(1970, 1, 1, 0, 0, 0).unwrap() - TimeDelta::seconds(1_000_000_000), +//! Utc.and_ymd_and_hms(1938, 4, 24, 22, 13, 20).unwrap()); //! ``` //! //! ### Formatting and Parsing @@ -241,7 +241,7 @@ //! # fn test() { //! use chrono::Locale; //! -//! let dt = Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(); +//! let dt = Utc.and_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(); //! assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2014-11-28 12:00:09"); //! assert_eq!(dt.format("%a %b %e %T %Y").to_string(), "Fri Nov 28 12:00:09 2014"); //! assert_eq!( @@ -290,7 +290,7 @@ //! ```rust //! use chrono::prelude::*; //! -//! let dt = Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(); +//! let dt = Utc.and_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(); //! let fixed_dt = dt.with_timezone(&FixedOffset::east(9*3600).unwrap()); //! //! // method 1 diff --git a/src/month.rs b/src/month.rs index e7c0b65305..1d11df118b 100644 --- a/src/month.rs +++ b/src/month.rs @@ -15,7 +15,7 @@ use crate::OutOfRange; /// use chrono::prelude::*; /// use chrono::Month; /// -/// let date = Utc.with_ymd_and_hms(2019, 10, 28, 9, 10, 11).unwrap(); +/// let date = Utc.and_ymd_and_hms(2019, 10, 28, 9, 10, 11).unwrap(); /// // `2019-10-28T09:10:11Z` /// let month = Month::try_from(u8::try_from(date.month()).unwrap()).ok(); /// assert_eq!(month, Some(Month::October)) @@ -25,7 +25,7 @@ use crate::OutOfRange; /// # use chrono::prelude::*; /// # use chrono::Month; /// let month = Month::January; -/// let dt = Utc.with_ymd_and_hms(2019, month.number_from_month(), 28, 9, 10, 11).unwrap(); +/// let dt = Utc.and_ymd_and_hms(2019, month.number_from_month(), 28, 9, 10, 11).unwrap(); /// assert_eq!((dt.year(), dt.month(), dt.day()), (2019, 1, 28)); /// ``` /// Allows mapping from and to month, from 1-January to 12-December. @@ -282,11 +282,11 @@ mod tests { assert_eq!(Month::try_from(12), Ok(Month::December)); assert_eq!(Month::try_from(13), Err(OutOfRange::new())); - let date = Utc.with_ymd_and_hms(2019, 10, 28, 9, 10, 11).unwrap(); + let date = Utc.and_ymd_and_hms(2019, 10, 28, 9, 10, 11).unwrap(); assert_eq!(Month::try_from(date.month() as u8), Ok(Month::October)); let month = Month::January; - let dt = Utc.with_ymd_and_hms(2019, month.number_from_month(), 28, 9, 10, 11).unwrap(); + let dt = Utc.and_ymd_and_hms(2019, month.number_from_month(), 28, 9, 10, 11).unwrap(); assert_eq!((dt.year(), dt.month(), dt.day()), (2019, 1, 28)); } diff --git a/src/naive/datetime/serde.rs b/src/naive/datetime/serde.rs index 2cf8e9ca16..6a99294b01 100644 --- a/src/naive/datetime/serde.rs +++ b/src/naive/datetime/serde.rs @@ -1140,7 +1140,7 @@ mod tests { } let expected = - Test { one: Some(1), two: Some(Utc.with_ymd_and_hms(1970, 1, 1, 0, 1, 1).unwrap()) }; + Test { one: Some(1), two: Some(Utc.and_ymd_and_hms(1970, 1, 1, 0, 1, 1).unwrap()) }; let bytes: Vec = serialize(&expected).unwrap(); let actual = deserialize::(&(bytes)).unwrap(); diff --git a/src/offset/fixed.rs b/src/offset/fixed.rs index ada184c7a9..76d3976e40 100644 --- a/src/offset/fixed.rs +++ b/src/offset/fixed.rs @@ -47,7 +47,7 @@ impl FixedOffset { /// let hour = 3600; /// let datetime = FixedOffset::east(5 * hour) /// .unwrap() - /// .with_ymd_and_hms(2016, 11, 08, 0, 0, 0) + /// .and_ymd_and_hms(2016, 11, 08, 0, 0, 0) /// .unwrap(); /// assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00+05:00") /// ``` @@ -73,7 +73,7 @@ impl FixedOffset { /// let hour = 3600; /// let datetime = FixedOffset::west(5 * hour) /// .unwrap() - /// .with_ymd_and_hms(2016, 11, 08, 0, 0, 0) + /// .and_ymd_and_hms(2016, 11, 08, 0, 0, 0) /// .unwrap(); /// assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00-05:00") /// ``` @@ -170,22 +170,22 @@ mod tests { // this makes everything easier! let offset = FixedOffset::east(86399).unwrap(); assert_eq!( - format!("{:?}", offset.with_ymd_and_hms(2012, 2, 29, 5, 6, 7).unwrap()), + format!("{:?}", offset.and_ymd_and_hms(2012, 2, 29, 5, 6, 7).unwrap()), "2012-02-29T05:06:07+23:59:59" ); let offset = FixedOffset::east(-86399).unwrap(); assert_eq!( - format!("{:?}", offset.with_ymd_and_hms(2012, 2, 29, 5, 6, 7).unwrap()), + format!("{:?}", offset.and_ymd_and_hms(2012, 2, 29, 5, 6, 7).unwrap()), "2012-02-29T05:06:07-23:59:59" ); let offset = FixedOffset::west(86399).unwrap(); assert_eq!( - format!("{:?}", offset.with_ymd_and_hms(2012, 3, 4, 5, 6, 7).unwrap()), + format!("{:?}", offset.and_ymd_and_hms(2012, 3, 4, 5, 6, 7).unwrap()), "2012-03-04T05:06:07-23:59:59" ); let offset = FixedOffset::west(-86399).unwrap(); assert_eq!( - format!("{:?}", offset.with_ymd_and_hms(2012, 3, 4, 5, 6, 7).unwrap()), + format!("{:?}", offset.and_ymd_and_hms(2012, 3, 4, 5, 6, 7).unwrap()), "2012-03-04T05:06:07+23:59:59" ); } diff --git a/src/offset/local/mod.rs b/src/offset/local/mod.rs index 2fa9191dc8..639be7064e 100644 --- a/src/offset/local/mod.rs +++ b/src/offset/local/mod.rs @@ -303,7 +303,7 @@ mod tests { #[test] fn test_local_date_sanity_check() { // issue #27 - assert_eq!(Local.with_ymd_and_hms(2999, 12, 28, 0, 0, 0).unwrap().day(), 28); + assert_eq!(Local.and_ymd_and_hms(2999, 12, 28, 0, 0, 0).unwrap().day(), 28); } #[test] diff --git a/src/offset/mod.rs b/src/offset/mod.rs index a2d1220161..9f3c741305 100644 --- a/src/offset/mod.rs +++ b/src/offset/mod.rs @@ -155,7 +155,7 @@ pub trait TimeZone: Sized + Clone { /// This assumes the proleptic Gregorian calendar, with the year 0 being 1 BCE. /// /// Returns `MappedLocalTime::None` on invalid input data. - fn with_ymd_and_hms( + fn and_ymd_and_hms( &self, year: i32, month: u32, diff --git a/src/offset/utc.rs b/src/offset/utc.rs index 8ccc55006a..dc146078d2 100644 --- a/src/offset/utc.rs +++ b/src/offset/utc.rs @@ -39,7 +39,7 @@ use crate::OutOfRange; /// let dt = DateTime::from_timestamp(61, 0).unwrap(); /// /// assert_eq!(Utc.and_timestamp(61, 0).unwrap(), dt); -/// assert_eq!(Utc.with_ymd_and_hms(1970, 1, 1, 0, 1, 1).unwrap(), dt); +/// assert_eq!(Utc.and_ymd_and_hms(1970, 1, 1, 0, 1, 1).unwrap(), dt); /// ``` #[derive(Copy, Clone, PartialEq, Eq, Hash)] #[cfg_attr( diff --git a/src/round.rs b/src/round.rs index d2ec45c2d3..c89969f584 100644 --- a/src/round.rs +++ b/src/round.rs @@ -277,7 +277,7 @@ pub enum RoundingError { /// /// ``` rust /// # use chrono::{DurationRound, TimeDelta, RoundingError, TimeZone, Utc}; - /// let dt = Utc.with_ymd_and_hms(2300, 12, 12, 0, 0, 0).unwrap(); + /// let dt = Utc.and_ymd_and_hms(2300, 12, 12, 0, 0, 0).unwrap(); /// /// assert_eq!(dt.duration_round(TimeDelta::days(1)), Err(RoundingError::TimestampExceedsLimit)); /// ``` @@ -503,7 +503,7 @@ mod tests { ); // timezone east - let dt = FixedOffset::east(3600).unwrap().with_ymd_and_hms(2020, 10, 27, 15, 0, 0).unwrap(); + let dt = FixedOffset::east(3600).unwrap().and_ymd_and_hms(2020, 10, 27, 15, 0, 0).unwrap(); assert_eq!( dt.duration_round(TimeDelta::days(1)).unwrap().to_string(), "2020-10-28 00:00:00 +01:00" @@ -514,7 +514,7 @@ mod tests { ); // timezone west - let dt = FixedOffset::west(3600).unwrap().with_ymd_and_hms(2020, 10, 27, 15, 0, 0).unwrap(); + let dt = FixedOffset::west(3600).unwrap().and_ymd_and_hms(2020, 10, 27, 15, 0, 0).unwrap(); assert_eq!( dt.duration_round(TimeDelta::days(1)).unwrap().to_string(), "2020-10-28 00:00:00 -01:00" @@ -590,7 +590,7 @@ mod tests { #[test] fn test_duration_round_pre_epoch() { - let dt = Utc.with_ymd_and_hms(1969, 12, 12, 12, 12, 12).unwrap(); + let dt = Utc.and_ymd_and_hms(1969, 12, 12, 12, 12, 12).unwrap(); assert_eq!( dt.duration_round(TimeDelta::minutes(10)).unwrap().to_string(), "1969-12-12 12:10:00 UTC" @@ -651,7 +651,7 @@ mod tests { ); // timezone east - let dt = FixedOffset::east(3600).unwrap().with_ymd_and_hms(2020, 10, 27, 15, 0, 0).unwrap(); + let dt = FixedOffset::east(3600).unwrap().and_ymd_and_hms(2020, 10, 27, 15, 0, 0).unwrap(); assert_eq!( dt.duration_trunc(TimeDelta::days(1)).unwrap().to_string(), "2020-10-27 00:00:00 +01:00" @@ -662,7 +662,7 @@ mod tests { ); // timezone west - let dt = FixedOffset::west(3600).unwrap().with_ymd_and_hms(2020, 10, 27, 15, 0, 0).unwrap(); + let dt = FixedOffset::west(3600).unwrap().and_ymd_and_hms(2020, 10, 27, 15, 0, 0).unwrap(); assert_eq!( dt.duration_trunc(TimeDelta::days(1)).unwrap().to_string(), "2020-10-27 00:00:00 -01:00" @@ -732,7 +732,7 @@ mod tests { #[test] fn test_duration_trunc_pre_epoch() { - let dt = Utc.with_ymd_and_hms(1969, 12, 12, 12, 12, 12).unwrap(); + let dt = Utc.and_ymd_and_hms(1969, 12, 12, 12, 12, 12).unwrap(); assert_eq!( dt.duration_trunc(TimeDelta::minutes(10)).unwrap().to_string(), "1969-12-12 12:10:00 UTC" diff --git a/tests/dateutils.rs b/tests/dateutils.rs index a6b2a78e1f..b94945c584 100644 --- a/tests/dateutils.rs +++ b/tests/dateutils.rs @@ -17,7 +17,7 @@ fn verify_against_date_command_local(path: &'static str, dt: NaiveDateTime) { // seems to be consistent with the output of the `date` command, so we simply // compare both. // let local = Local - // .with_ymd_and_hms(year, month, day, hour, 5, 1) + // .and_ymd_and_hms(year, month, day, hour, 5, 1) // // looks like the "date" command always returns a given time when it is ambiguous // .earliest();