Add try_to_rfc3339 and to_iso8601, deprecate to_rfc3339
          #1331
        
          
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Split out from #1144.
RFC 3339 is not defined for dates with a year outside of 0..=9999 (like RFC 2822). ISO 8601 does support it.
DateTime::to_rfc3339was a hybrid method, claiming to format a datetime as both valid RFC 3339 and ISO 8601. It would write invalid RFC 3339 strings if the year is out of range, which could not be parsed byDateTime::parse_from_rfc3339.I propose to deprecate
to_rfc3339, and replace it with two methods:try_to_rfc3339andto_iso8601.I did not make
to_rfc3339panic on out-of-range dates liketo_rfc2822, to not break existing uses.It is deprecated with the message: "Produces invalid data on years outside of the range 0..=9999. Use
try_to_rfc3339()orto_iso8601instead."For
DateTime::to_rfc3339_optsand theRFC3339formatting item (used for"%+") I only made some documentation adjustments that they format the value an ISO 8601 representation when the year is out of range.