From 595955c4821a9450c28355d5825d8813fa82f566 Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Fri, 12 May 2023 06:50:03 +0200 Subject: [PATCH] Add test for `impl From> for DateTime` --- src/datetime/tests.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/datetime/tests.rs b/src/datetime/tests.rs index 08d94afc8c..d35a56ff5c 100644 --- a/src/datetime/tests.rs +++ b/src/datetime/tests.rs @@ -4,7 +4,7 @@ use super::DateTime; use crate::naive::{NaiveDate, NaiveTime}; #[cfg(feature = "clock")] use crate::offset::Local; -use crate::offset::{FixedOffset, TimeZone, Utc}; +use crate::offset::{FixedOffset, Offset, TimeZone, Utc}; use crate::oldtime::Duration; use crate::{Datelike, Days, LocalResult, Months, NaiveDateTime}; @@ -983,3 +983,14 @@ fn test_from_naive_date_time_windows() { }); assert!(err.is_err()); } + +#[test] +fn test_datetime_local_from_preserves_offset() { + let naivedatetime = NaiveDate::from_ymd_opt(2023, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(); + + let datetime = Local.from_utc_datetime(&naivedatetime); + let offset = datetime.offset().fix(); + + let datetime_fixed: DateTime = datetime.into(); + assert_eq!(&offset, datetime_fixed.offset()); +}