From cff188fc77082548e9bf2bf5bb1867f4f845f481 Mon Sep 17 00:00:00 2001 From: Brennan Vincent Date: Tue, 13 Dec 2022 09:06:36 -0500 Subject: [PATCH 1/2] Test that `from_timestamp_millis` corresponds to `from_timestamp_opt` --- src/naive/datetime/tests.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/naive/datetime/tests.rs b/src/naive/datetime/tests.rs index 3df475b9c1..f026643ae1 100644 --- a/src/naive/datetime/tests.rs +++ b/src/naive/datetime/tests.rs @@ -29,6 +29,16 @@ fn test_datetime_from_timestamp_millis() { let naive_datetime = NaiveDateTime::from_timestamp_millis(timestamp_millis); assert!(naive_datetime.is_none()); } + + // Test that the result of `from_timestamp_millis` compares equal to + // that of `from_timestamp_opt`. + let secs_test = [0, 1, 2, 1000, 1234, 12345678, -1, -2, -1000, -12345678]; + for secs in secs_test { + assert_eq!( + NaiveDateTime::from_timestamp_millis(secs * 1000), + NaiveDateTime::from_timestamp_opt(secs, 0) + ); + } } #[test] From 08b6f5f2b614d9fba3a223da49d536bbf7f41702 Mon Sep 17 00:00:00 2001 From: Brennan Vincent Date: Tue, 13 Dec 2022 16:08:04 -0500 Subject: [PATCH 2/2] Fix MSRV violation --- src/naive/datetime/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/naive/datetime/tests.rs b/src/naive/datetime/tests.rs index f026643ae1..806268d817 100644 --- a/src/naive/datetime/tests.rs +++ b/src/naive/datetime/tests.rs @@ -33,7 +33,7 @@ fn test_datetime_from_timestamp_millis() { // Test that the result of `from_timestamp_millis` compares equal to // that of `from_timestamp_opt`. let secs_test = [0, 1, 2, 1000, 1234, 12345678, -1, -2, -1000, -12345678]; - for secs in secs_test { + for secs in secs_test.iter().cloned() { assert_eq!( NaiveDateTime::from_timestamp_millis(secs * 1000), NaiveDateTime::from_timestamp_opt(secs, 0)