@@ -154,7 +154,10 @@ fn test_datetime_from_timestamp_millis() {
154154 // that of `from_timestamp_opt`.
155155 let secs_test = [ 0 , 1 , 2 , 1000 , 1234 , 12345678 , -1 , -2 , -1000 , -12345678 ] ;
156156 for secs in secs_test. iter ( ) . cloned ( ) {
157- assert_eq ! ( DateTime :: from_timestamp_millis( secs * 1000 ) , DateTime :: from_timestamp( secs, 0 ) ) ;
157+ assert_eq ! (
158+ DateTime :: from_timestamp_millis( secs * 1000 ) ,
159+ DateTime :: from_timestamp_secs( secs)
160+ ) ;
158161 }
159162}
160163
@@ -191,7 +194,7 @@ fn test_datetime_from_timestamp_micros() {
191194 for secs in secs_test. iter ( ) . copied ( ) {
192195 assert_eq ! (
193196 DateTime :: from_timestamp_micros( secs * 1_000_000 ) ,
194- DateTime :: from_timestamp ( secs, 0 )
197+ DateTime :: from_timestamp_secs ( secs)
195198 ) ;
196199 }
197200}
@@ -242,24 +245,34 @@ fn test_datetime_from_timestamp_nanos() {
242245 for secs in secs_test. iter ( ) . copied ( ) {
243246 assert_eq ! (
244247 Some ( DateTime :: from_timestamp_nanos( secs * 1_000_000_000 ) ) ,
245- DateTime :: from_timestamp ( secs, 0 )
248+ DateTime :: from_timestamp_secs ( secs)
246249 ) ;
247250 }
248251}
249252
253+ #[ test]
254+ fn test_datetime_from_timestamp_secs ( ) {
255+ let valid = [ -2208936075 , 0 , 119731017 , 1234567890 , 2034061609 ] ;
256+
257+ for timestamp_secs in valid. iter ( ) . copied ( ) {
258+ let datetime = DateTime :: from_timestamp_secs ( timestamp_secs) . unwrap ( ) ;
259+ assert_eq ! ( timestamp_secs, datetime. timestamp( ) ) ;
260+ assert_eq ! ( DateTime :: from_timestamp( timestamp_secs, 0 ) . unwrap( ) , datetime) ;
261+ }
262+ }
263+
250264#[ test]
251265fn test_datetime_from_timestamp ( ) {
252- let from_timestamp = |secs| DateTime :: from_timestamp ( secs, 0 ) ;
253266 let ymdhms = |y, m, d, h, n, s| {
254267 NaiveDate :: from_ymd_opt ( y, m, d) . unwrap ( ) . and_hms_opt ( h, n, s) . unwrap ( ) . and_utc ( )
255268 } ;
256- assert_eq ! ( from_timestamp ( -1 ) , Some ( ymdhms( 1969 , 12 , 31 , 23 , 59 , 59 ) ) ) ;
257- assert_eq ! ( from_timestamp ( 0 ) , Some ( ymdhms( 1970 , 1 , 1 , 0 , 0 , 0 ) ) ) ;
258- assert_eq ! ( from_timestamp ( 1 ) , Some ( ymdhms( 1970 , 1 , 1 , 0 , 0 , 1 ) ) ) ;
259- assert_eq ! ( from_timestamp ( 1_000_000_000 ) , Some ( ymdhms( 2001 , 9 , 9 , 1 , 46 , 40 ) ) ) ;
260- assert_eq ! ( from_timestamp ( 0x7fffffff ) , Some ( ymdhms( 2038 , 1 , 19 , 3 , 14 , 7 ) ) ) ;
261- assert_eq ! ( from_timestamp ( i64 :: MIN ) , None ) ;
262- assert_eq ! ( from_timestamp ( i64 :: MAX ) , None ) ;
269+ assert_eq ! ( DateTime :: from_timestamp_secs ( -1 ) , Some ( ymdhms( 1969 , 12 , 31 , 23 , 59 , 59 ) ) ) ;
270+ assert_eq ! ( DateTime :: from_timestamp_secs ( 0 ) , Some ( ymdhms( 1970 , 1 , 1 , 0 , 0 , 0 ) ) ) ;
271+ assert_eq ! ( DateTime :: from_timestamp_secs ( 1 ) , Some ( ymdhms( 1970 , 1 , 1 , 0 , 0 , 1 ) ) ) ;
272+ assert_eq ! ( DateTime :: from_timestamp_secs ( 1_000_000_000 ) , Some ( ymdhms( 2001 , 9 , 9 , 1 , 46 , 40 ) ) ) ;
273+ assert_eq ! ( DateTime :: from_timestamp_secs ( 0x7fffffff ) , Some ( ymdhms( 2038 , 1 , 19 , 3 , 14 , 7 ) ) ) ;
274+ assert_eq ! ( DateTime :: from_timestamp_secs ( i64 :: MIN ) , None ) ;
275+ assert_eq ! ( DateTime :: from_timestamp_secs ( i64 :: MAX ) , None ) ;
263276}
264277
265278#[ test]
0 commit comments