@@ -457,12 +457,12 @@ fn test_datetime_rfc2822() {
457457
458458 // timezone 0
459459 assert_eq ! (
460- Utc . with_ymd_and_hms( 2015 , 2 , 18 , 23 , 16 , 9 ) . unwrap( ) . to_rfc2822 ( ) ,
461- "Wed, 18 Feb 2015 23:16:09 +0000"
460+ Utc . with_ymd_and_hms( 2015 , 2 , 18 , 23 , 16 , 9 ) . unwrap( ) . try_to_rfc2822 ( ) . as_deref ( ) ,
461+ Some ( "Wed, 18 Feb 2015 23:16:09 +0000" )
462462 ) ;
463463 assert_eq ! (
464- Utc . with_ymd_and_hms( 2015 , 2 , 1 , 23 , 16 , 9 ) . unwrap( ) . to_rfc2822 ( ) ,
465- "Sun, 1 Feb 2015 23:16:09 +0000"
464+ Utc . with_ymd_and_hms( 2015 , 2 , 1 , 23 , 16 , 9 ) . unwrap( ) . try_to_rfc2822 ( ) . as_deref ( ) ,
465+ Some ( "Sun, 1 Feb 2015 23:16:09 +0000" )
466466 ) ;
467467 // timezone +05
468468 assert_eq ! (
@@ -473,8 +473,9 @@ fn test_datetime_rfc2822() {
473473 . unwrap( )
474474 )
475475 . unwrap( )
476- . to_rfc2822( ) ,
477- "Wed, 18 Feb 2015 23:16:09 +0500"
476+ . try_to_rfc2822( )
477+ . as_deref( ) ,
478+ Some ( "Wed, 18 Feb 2015 23:16:09 +0500" )
478479 ) ;
479480 assert_eq ! (
480481 DateTime :: parse_from_rfc2822( "Wed, 18 Feb 2015 23:59:60 +0500" ) ,
@@ -508,8 +509,9 @@ fn test_datetime_rfc2822() {
508509 . unwrap( )
509510 )
510511 . unwrap( )
511- . to_rfc2822( ) ,
512- "Wed, 18 Feb 2015 23:59:60 +0500"
512+ . try_to_rfc2822( )
513+ . as_deref( ) ,
514+ Some ( "Wed, 18 Feb 2015 23:59:60 +0500" )
513515 ) ;
514516
515517 assert_eq ! (
@@ -521,8 +523,8 @@ fn test_datetime_rfc2822() {
521523 Ok ( FixedOffset :: east_opt( 0 ) . unwrap( ) . with_ymd_and_hms( 2015 , 2 , 18 , 23 , 16 , 9 ) . unwrap( ) )
522524 ) ;
523525 assert_eq ! (
524- ymdhms_micro( & edt, 2015 , 2 , 18 , 23 , 59 , 59 , 1_234_567 ) . to_rfc2822 ( ) ,
525- "Wed, 18 Feb 2015 23:59:60 +0500"
526+ ymdhms_micro( & edt, 2015 , 2 , 18 , 23 , 59 , 59 , 1_234_567 ) . try_to_rfc2822 ( ) . as_deref ( ) ,
527+ Some ( "Wed, 18 Feb 2015 23:59:60 +0500" )
526528 ) ;
527529 assert_eq ! (
528530 DateTime :: parse_from_rfc2822( "Wed, 18 Feb 2015 23:59:58 +0500" ) ,
@@ -1339,8 +1341,8 @@ fn test_min_max_getters() {
13391341 let beyond_max = offset_max. from_utc_datetime ( & NaiveDateTime :: MAX ) ;
13401342
13411343 assert_eq ! ( format!( "{:?}" , beyond_min) , "-262144-12-31T22:00:00-02:00" ) ;
1342- // RFC 2822 doesn't support years with more than 4 digits.
1343- // assert_eq!(beyond_min.to_rfc2822 (), "");
1344+ # [ cfg ( feature = "alloc" ) ]
1345+ assert_eq ! ( beyond_min. try_to_rfc2822 ( ) , None ) ; // doesn't support years with more than 4 digits.
13441346 #[ cfg( feature = "alloc" ) ]
13451347 assert_eq ! ( beyond_min. to_rfc3339( ) , "-262144-12-31T22:00:00-02:00" ) ;
13461348 #[ cfg( feature = "alloc" ) ]
@@ -1364,8 +1366,8 @@ fn test_min_max_getters() {
13641366 assert_eq ! ( beyond_min. nanosecond( ) , 0 ) ;
13651367
13661368 assert_eq ! ( format!( "{:?}" , beyond_max) , "+262143-01-01T01:59:59.999999999+02:00" ) ;
1367- // RFC 2822 doesn't support years with more than 4 digits.
1368- // assert_eq!(beyond_max.to_rfc2822 (), "");
1369+ # [ cfg ( feature = "alloc" ) ]
1370+ assert_eq ! ( beyond_max. try_to_rfc2822 ( ) , None ) ; // doesn't support years with more than 4 digits.
13691371 #[ cfg( feature = "alloc" ) ]
13701372 assert_eq ! ( beyond_max. to_rfc3339( ) , "+262143-01-01T01:59:59.999999999+02:00" ) ;
13711373 #[ cfg( feature = "alloc" ) ]
0 commit comments