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

ISO8601 date parser that preserves the timezone offset information #967

Open
simonjbeaumont opened this issue Oct 8, 2024 · 1 comment
Labels
API Change Any changes to Foundation's public API surface

Comments

@simonjbeaumont
Copy link

Currently, the ISO8601 date parser, ISO8601DateFormatter.date(from:) parses an ISO8601 date string into a Date.

The parsing strategy correctly handles the timezone offset, but this information is then lost, because Date itself is not timezone aware:

import Foundation
let dateString = "2024-10-08T08:12:34-08:00"
let date = ISO8601DateFormatter().date(from: dateString)!  // timezone offset lost

There are use cases that would like to parse such a string and also know what timezone the date was formatted in. It would be great to have API for returning a timezone-aware value, or even just to return the offset alongside the Date.

@parkera
Copy link
Contributor

parkera commented Oct 8, 2024

Returning a DateComponents would be a great way to address this and unlock other use cases as well.

@itingliu itingliu added the API Change Any changes to Foundation's public API surface label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Change Any changes to Foundation's public API surface
Projects
None yet
Development

No branches or pull requests

3 participants