swiftlang / swift-foundation

The Foundation project
Apache License 2.0
2.36k stars 150 forks source link

ISO8601DateFormatter does not handle extreme dates #118

Open ozantepe opened 1 year ago

ozantepe commented 1 year ago

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

tbkka commented 1 year ago

CC: @parkera

AnthonyLatsis commented 1 year ago

Foundation for macOS is a proprietary framework; please report this issue at https://feedbackassistant.apple.com/ instead. You may include the feedback ID here

parkera commented 1 year ago

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.

ozantepe commented 1 year ago

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

AnthonyLatsis commented 1 year ago

@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?

parkera commented 1 year ago

Sure. With respect to this specific bug, though, we'll be focusing on Date.ISO8601FormatStyle instead of the legacy Formatter types.

parkera commented 1 year ago

(this ER may still be relevant to that style API though)

AnthonyLatsis commented 1 year ago

@shahmishal Will you please do the transfer?

AnthonyLatsis commented 1 year ago

(this ER may still be relevant to that style API though)

What does "ER" stand for?

parkera commented 1 year ago

Apologies for the jargon. ER is short for enhancement request.

ozantepe commented 1 year ago

@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.

AnthonyLatsis commented 1 year ago

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.

itingliu commented 1 year ago

related: https://github.com/apple/swift-foundation/issues/46