From 17bbef7545d4bd1af263c4a8548a53bac91b4b0a Mon Sep 17 00:00:00 2001 From: jtmoon79 <815261+jtmoon79@users.noreply.github.com> Date: Sat, 27 May 2023 20:30:20 -0700 Subject: [PATCH] Add more DateTime.into tests More tests for combinations of `DateTime::into`. Follow-up to Pull Request #271. --- src/datetime/mod.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 2e9203a307..913a219b36 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -1269,7 +1269,7 @@ fn test_add_sub_months() { } #[test] -fn test_auto_conversion() { +fn test_auto_conversion_fixedoffset_into_utc() { let utc_dt = Utc.with_ymd_and_hms(2018, 9, 5, 23, 58, 0).unwrap(); let cdt_dt = FixedOffset::west_opt(5 * 60 * 60) .unwrap() @@ -1279,6 +1279,33 @@ fn test_auto_conversion() { assert_eq!(utc_dt, utc_dt2); } +#[test] +fn test_auto_conversion_utc_into_fixedoffset() { + let utc_dt = Utc.with_ymd_and_hms(2018, 9, 5, 23, 58, 0).unwrap(); + let cdt_dt = FixedOffset::west_opt(5 * 60 * 60) + .unwrap() + .with_ymd_and_hms(2018, 9, 5, 18, 58, 0) + .unwrap(); + let cdt_dt2: DateTime = utc_dt.into(); + assert_eq!(cdt_dt, cdt_dt2); +} + +#[cfg(feature = "clock")] +#[test] +fn test_auto_conversion_local_into_utc() { + let loc_dt = Local.with_ymd_and_hms(2020, 1, 2, 3, 4, 5).unwrap(); + let utc_dt: DateTime = loc_dt.into(); + assert_eq!(utc_dt, loc_dt); +} + +#[cfg(feature = "clock")] +#[test] +fn test_auto_conversion_utc_into_local() { + let utc_dt = Utc.with_ymd_and_hms(2020, 1, 2, 3, 4, 5).unwrap(); + let loc_dt: DateTime = utc_dt.into(); + assert_eq!(utc_dt, loc_dt); +} + #[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))] fn test_encodable_json(to_string_utc: FUtc, to_string_fixed: FFixed) where