@@ -452,6 +452,7 @@ fn test_datetime_with_timezone() {
452
452
453
453
#[ test]
454
454
#[ cfg( feature = "alloc" ) ]
455
+ #[ allow( deprecated) ]
455
456
fn test_datetime_rfc2822 ( ) {
456
457
let edt = FixedOffset :: east_opt ( 5 * 60 * 60 ) . unwrap ( ) ;
457
458
@@ -576,6 +577,31 @@ fn test_datetime_rfc2822() {
576
577
assert ! ( DateTime :: parse_from_rfc2822( "Wed. 18 Feb 2015 23:16:09 +0000" ) . is_err( ) ) ;
577
578
// *trailing* space causes failure
578
579
assert ! ( DateTime :: parse_from_rfc2822( "Wed, 18 Feb 2015 23:16:09 +0000 " ) . is_err( ) ) ;
580
+
581
+ const RFC_2822_YEAR_MAX : i32 = 9999 ;
582
+ const RFC_2822_YEAR_MIN : i32 = 0 ;
583
+
584
+ let dt = Utc . with_ymd_and_hms ( RFC_2822_YEAR_MAX , 1 , 2 , 3 , 4 , 5 ) . unwrap ( ) ;
585
+ assert_eq ! ( dt. to_rfc2822( ) , "Sat, 2 Jan 9999 03:04:05 +0000" ) ;
586
+
587
+ let dt = Utc . with_ymd_and_hms ( RFC_2822_YEAR_MIN , 1 , 2 , 3 , 4 , 5 ) . unwrap ( ) ;
588
+ assert_eq ! ( dt. to_rfc2822( ) , "Sun, 2 Jan 0000 03:04:05 +0000" ) ;
589
+ }
590
+
591
+ #[ test]
592
+ #[ should_panic]
593
+ #[ cfg( feature = "alloc" ) ]
594
+ #[ allow( deprecated) ]
595
+ fn test_rfc_2822_year_range_panic_high ( ) {
596
+ let _ = Utc . with_ymd_and_hms ( 10000 , 1 , 2 , 3 , 4 , 5 ) . unwrap ( ) . to_rfc2822 ( ) ;
597
+ }
598
+
599
+ #[ test]
600
+ #[ should_panic]
601
+ #[ cfg( feature = "alloc" ) ]
602
+ #[ allow( deprecated) ]
603
+ fn test_rfc_2822_year_range_panic_low ( ) {
604
+ let _ = Utc . with_ymd_and_hms ( -1 , 1 , 2 , 3 , 4 , 5 ) . unwrap ( ) . to_rfc2822 ( ) ;
579
605
}
580
606
581
607
#[ test]
0 commit comments