@@ -640,6 +640,7 @@ fn test_datetime_with_timezone() {
640640
641641#[ test]
642642#[ cfg( feature = "alloc" ) ]
643+ #[ allow( deprecated) ]
643644fn test_datetime_rfc2822 ( ) {
644645 let edt = FixedOffset :: east_opt ( 5 * 60 * 60 ) . unwrap ( ) ;
645646
@@ -764,6 +765,31 @@ fn test_datetime_rfc2822() {
764765 assert ! ( DateTime :: parse_from_rfc2822( "Wed. 18 Feb 2015 23:16:09 +0000" ) . is_err( ) ) ;
765766 // *trailing* space causes failure
766767 assert ! ( DateTime :: parse_from_rfc2822( "Wed, 18 Feb 2015 23:16:09 +0000 " ) . is_err( ) ) ;
768+
769+ const RFC_2822_YEAR_MAX : i32 = 9999 ;
770+ const RFC_2822_YEAR_MIN : i32 = 0 ;
771+
772+ let dt = Utc . with_ymd_and_hms ( RFC_2822_YEAR_MAX , 1 , 2 , 3 , 4 , 5 ) . unwrap ( ) ;
773+ assert_eq ! ( dt. to_rfc2822( ) , "Sat, 2 Jan 9999 03:04:05 +0000" ) ;
774+
775+ let dt = Utc . with_ymd_and_hms ( RFC_2822_YEAR_MIN , 1 , 2 , 3 , 4 , 5 ) . unwrap ( ) ;
776+ assert_eq ! ( dt. to_rfc2822( ) , "Sun, 2 Jan 0000 03:04:05 +0000" ) ;
777+ }
778+
779+ #[ test]
780+ #[ should_panic]
781+ #[ cfg( feature = "alloc" ) ]
782+ #[ allow( deprecated) ]
783+ fn test_rfc_2822_year_range_panic_high ( ) {
784+ let _ = Utc . with_ymd_and_hms ( 10000 , 1 , 2 , 3 , 4 , 5 ) . unwrap ( ) . to_rfc2822 ( ) ;
785+ }
786+
787+ #[ test]
788+ #[ should_panic]
789+ #[ cfg( feature = "alloc" ) ]
790+ #[ allow( deprecated) ]
791+ fn test_rfc_2822_year_range_panic_low ( ) {
792+ let _ = Utc . with_ymd_and_hms ( -1 , 1 , 2 , 3 , 4 , 5 ) . unwrap ( ) . to_rfc2822 ( ) ;
767793}
768794
769795#[ test]
0 commit comments