Skip to content

Commit

Permalink
Add test for impl From<DateTime<Local>> for DateTime<FixedOffset>
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker authored and djc committed May 12, 2023
1 parent 38d9132 commit 595955c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<FixedOffset> = datetime.into();
assert_eq!(&offset, datetime_fixed.offset());
}

0 comments on commit 595955c

Please sign in to comment.