Skip to content

Commit

Permalink
Add more DateTime.into tests
Browse files Browse the repository at this point in the history
More tests for combinations of `DateTime::into`.

Follow-up to Pull Request chronotope#271.
  • Loading branch information
jtmoon79 committed May 28, 2023
1 parent 656c941 commit 17bbef7
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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<FixedOffset> = 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<Utc> = 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<Local> = utc_dt.into();
assert_eq!(utc_dt, loc_dt);
}

#[cfg(all(test, any(feature = "rustc-serialize", feature = "serde")))]
fn test_encodable_json<FUtc, FFixed, E>(to_string_utc: FUtc, to_string_fixed: FFixed)
where
Expand Down

0 comments on commit 17bbef7

Please sign in to comment.