ISO8601DateFormatter does not handle extreme dates
Description
ISO8601 standard allows representing years before 0000 or after 9999 using a "-" or "+" sign as prefix to four digits (±YYYYY). Apparently, there is no option in Swift's current ISO8601DateFormatter that enables such formatting, which causes errors in systems where there is such an agreement with client and server to follow that standard option.
Steps to reproduce
import Foundation
let date = Date(timeIntervalSince1970: 253402300800) // January 1, 10000
let formatter = ISO8601DateFormatter()
let formattedDateString = formatter.string(from: date) // "10000-01-01T00:00:00Z"
print(formattedDateString)
Expected behavior
Expected formattedDateString to be "+10000-01-01T00:00:00Z" (either with the default ISO8601DateFormatter implementation or with an option provided within the ISO8601DateFormatter.Options and setting it on formatter instance explicitly) in order to be compliant with ISO8601.
Environment
- Swift compiler version info
- swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
- Target: arm64-apple-macosx12.0
CC: @parkera
Foundation for macOS is a proprietary framework; please report this issue at https://feedbackassistant.apple.com/ instead. You may include the feedback ID here
We’re in the process of moving this type, among others, to a more open model. Having bug reports like this open still seems valuable to me, even if we don’t have an immediate fix.
Hey 👋 It's been some time and I totally forgot to report this issue at feedbackassistant. Sorry for the late, I've just reported it there as well and I share the feedback ID here for reference: 12179169
@parkera Would it be appropriate to transfer this and other Foundation issues tracked in this repository to swift-foundation now that it has been published?
Sure. With respect to this specific bug, though, we'll be focusing on Date.ISO8601FormatStyle instead of the legacy Formatter types.
(this ER may still be relevant to that style API though)
@shahmishal Will you please do the transfer?
(this ER may still be relevant to that style API though)
What does "ER" stand for?
Apologies for the jargon. ER is short for enhancement request.
@shahmishal Will you please do the transfer?
@AnthonyLatsis, if what you mean by "transfer" is to create the issue on swift-foundation, I can do that.
What I mean is to actually move the issue under swift-foundation (there is a GitHub feature for doing this, but you need write access to both ends). I prefer transferring over cloning because it avoids a dupe, de-pollutes the source repository’s issue database, and saves us the trouble of classifying leftover issues in repos they don‘t belong in.
related: https://github.com/apple/swift-foundation/issues/46