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

JSONTransformableDateFormatter doesn't transform dates properly #10

Closed
tomparkp opened this issue Nov 9, 2015 · 1 comment
Closed

Comments

@tomparkp
Copy link

tomparkp commented Nov 9, 2015

The current NSDateFormatter for transforming ISO8601 appears to have some issues with regards to the date format:

dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

First putting the 'Z' in single quotes seems to escape it so that it always assumes the date string is in GMT therefore ignoring timezone offset included in the string.

For example if I use ModelRocket to parse the following date string from my JSON:
"2015-10-04T01:00:00.000Z"

I actually end up with:
"2015-10-04T05:00:00.000Z"

This is because by default NSDateFormatter uses the local timezone of the device (in my case EST) so when this combines with the escaped Z the time is off by 4 hours.

This can be corrected by eliminating the single quotes around the Z so it accepts the offsets properly.

Additionally having the SSS means that the example string 2015-05-31T19:00:17+00:00 from the documentation will fail to parse because its missing milliseconds.

The last thing is that its recommended to add the following just in case the device is not using the gregorian calendar:

formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")

dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

jlandon added a commit that referenced this issue Nov 18, 2015
@jlandon
Copy link
Member

jlandon commented Nov 18, 2015

@tompark-IO thanks for the tip! This is fixed in 1.2.2. Cheers!

@jlandon jlandon closed this as completed Nov 18, 2015
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

No branches or pull requests

2 participants