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

-fix date formatting and add tests #434

Merged
merged 12 commits into from
Nov 2, 2020

Conversation

sbenedicadb
Copy link
Member

@sbenedicadb sbenedicadb commented Oct 28, 2020

func getISO8601Date() -> String {
let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
Copy link
Contributor

@shalehaha shalehaha Oct 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm a little bit concerned about removing the locale. it might generate the numbers in another language.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that handled by ISO8601DateFormatter ?

formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.setLocalizedDateFormatFromTemplate("yyyy-MM-dd'T'HH:mm:ssZZZ")
return formatter.string(from: self)
let formatter = ISO8601DateFormatter()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use DateFormatter instead of ISO8601DateFormatter?
When working with fixed format dates, such as RFC 3339, you set the dateFormat property to specify a format string. For most fixed formats, you should also set the locale property to a POSIX locale ("en_US_POSIX"), and set the timeZone property to UTC.
-- from Apple

Here is my sample code:

let formatter = DateFormatter()
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZ"
print(formatter.string(from: Date()))
//2020-10-29T12:52:42-0600

@codecov
Copy link

codecov bot commented Nov 2, 2020

Codecov Report

Merging #434 into dev will increase coverage by 0.30%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev     #434      +/-   ##
==========================================
+ Coverage   87.14%   87.43%   +0.30%     
==========================================
  Files          92       92              
  Lines        4042     4042              
==========================================
+ Hits         3522     3534      +12     
+ Misses        520      508      -12     

@sbenedicadb
Copy link
Member Author

@shalehaha quick! while it's green!

@shalehaha shalehaha merged commit 2dfd929 into adobe:dev Nov 2, 2020
@sbenedicadb sbenedicadb deleted the fix-date-formatter branch December 8, 2022 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants