Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-9266] ISO8601DateFormatter 'withInternetDateTime' option - unexpected behavior #3589

Open
swift-ci opened this issue Nov 15, 2018 · 0 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-9266
Radar None
Original Reporter arim (JIRA User)
Type Bug
Environment

Xcode 10.1

Mac OSX 10.13.6

Swift 4.2

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 7a12b63531bd9c010297e479a0d72ba9

Issue Description:

ISO8601DateFormatter shows unexpected and against-its-documentation behavior related to numeric time zone offset (ref. RFC 3339).

From the ISO8601DateFormatter.Options Documentation:

Format Example Options
RFC 3339Date and Time 2016-06-13T16:00:00+00:00 {{[withInternetDateTime\ apple-reference-documentation://hsh3BZ89je]}}

The Option withInternetDateTime is composed and contains {{withColonSeparatorInTimeZone }}amongst other things. The expected behavior for formatting a date into a String is reflected in the Example Column above.

Actual Behavior:

Figure 1 - ISO8601DateFormatter

let input = "2017-01-06T08:45:00+00:00"
let formatter = ISO8601DateFormatter()
formatter.formatOptions = .withInternetDateTime
formatter.timeZone = TimeZone(identifier: "GMT")!
formatter.string(from: formatter.date(from: input)!)
// prints "2017-01-06T08:45:00Z"
Expected "2017-01-06T08:45:00+00:00"  

Even though Z stands for +00:00, this is not according to the documentation and/or the specified {{ISO8601DateFormatter.Options }}value.

Same applies for Figure 2, the underlying DateFormatter

Figure 2 - DateFormatter

let input = "2017-01-06T08:45:00+00:00"
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
formatter.timeZone = TimeZone(identifier: "GMT")!
formatter.string(from: formatter.date(from: input)!)
// prints "2017-01-06T08:45:00Z"
 Expected "2017-01-06T08:45:00+00:00"    

ZZZZZ is expected to output the "long" numeric time zone offset. Showing Z is inconsistent with actual offset behavior.

To show even more inconsistency, Figure 3 would expect the same behavior as above, but results in this:

Figure 3 - DateFormatter

let input = "2017-01-06T08:45:00+00:00"
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
formatter.timeZone = TimeZone(identifier: "GMT")!
formatter.string(from: formatter.date(from: input)!)
// prints "2017-01-06T08:45:00+0000"
Expectation, based on Fig. 1 & Fig. 2: "2017-01-06T08:45:00Z"      

This only applies for zero offsets (where Z would be appropriate), but because this is showing inconsistent behavior in documentation and {{ISO8601DateFormatter }}Implementation, I decided to open this bug.

If requested, I can look through the source code and open a pull request, if I manage to find the underlying issue here.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant