swift-foundation icon indicating copy to clipboard operation
swift-foundation copied to clipboard

ISO8601DateFormatter does not handle extreme dates

Open ozantepe opened this issue 2 years ago • 13 comments

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

ozantepe avatar Jan 02 '23 20:01 ozantepe

CC: @parkera

tbkka avatar Jan 03 '23 14:01 tbkka

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

AnthonyLatsis avatar Jan 08 '23 18:01 AnthonyLatsis

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.

parkera avatar Jan 08 '23 22:01 parkera

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

ozantepe avatar May 09 '23 19:05 ozantepe

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

AnthonyLatsis avatar May 10 '23 12:05 AnthonyLatsis

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

parkera avatar May 10 '23 19:05 parkera

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

parkera avatar May 10 '23 19:05 parkera

@shahmishal Will you please do the transfer?

AnthonyLatsis avatar May 10 '23 19:05 AnthonyLatsis

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

What does "ER" stand for?

AnthonyLatsis avatar May 10 '23 19:05 AnthonyLatsis

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

parkera avatar May 10 '23 20:05 parkera

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

ozantepe avatar May 12 '23 14:05 ozantepe

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.

AnthonyLatsis avatar May 12 '23 14:05 AnthonyLatsis

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

itingliu avatar May 12 '23 18:05 itingliu