wvteijlingen / Spine

A Swift library for working with JSON:API APIs. It supports mapping to custom model classes, fetching, advanced querying, linking and persisting.
MIT License
266 stars 109 forks source link

Fixes date attributes not returning in UTC #25

Closed kurko closed 8 years ago

kurko commented 9 years ago

My timezone is -3, so I couldn't even run it locally because the test was expecting it to be -1.

kurko commented 9 years ago

yay my first iOS PR

wvteijlingen commented 9 years ago

Thanks for the PR! The tests were indeed incorrect in assuming a timezone. I think however that this is purely a test issue and should not be fixed in the DateFormatter. IMHO the DateFormatter should just return an NSDate from the String, without doing any timezone modifications.

What are your thoughts on this?

kurko commented 9 years ago

Whatever you prefer. I'll change it later.

kurko commented 9 years ago

Ok, done. Ready for review :smile:

wvteijlingen commented 9 years ago

I appreciate the work you put in, but I think this can be resolved in an easier way:

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
XCTAssertEqual(json["data"]["attributes"]["dateAttribute"].stringValue, dateFormatter.stringFromDate(foo.dateAttribute!), "Serialized date is not equal.")

I any case, I think we should split the serialization tests into separate tests for each kind of attribute. That way we can also test using different date formats.