-
Notifications
You must be signed in to change notification settings - Fork 40
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
Conversation
func getISO8601Date() -> String { | ||
let formatter = DateFormatter() | ||
formatter.locale = Locale(identifier: "en_US_POSIX") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 Report
@@ 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 |
@shalehaha quick! while it's green! |
#435