boredzo / iso-8601-date-formatter

A Cocoa NSFormatter subclass to convert dates to and from ISO-8601-formatted strings. Supports calendar, week, and ordinal formats.
http://boredzo.org/iso8601dateformatter/
Other
600 stars 140 forks source link

How do I create a date string from a date without including any daylight saving? #5

Closed qnoid closed 11 years ago

qnoid commented 11 years ago
NSString* dateString = @"2012-04-01T15:37:53Z";

ISO8601DateFormatter *dateFormat = [[ISO8601DateFormatter alloc] init];
[dateFormat setIncludeTime:YES];
NSTimeZone *utcTimeZone = [NSTimeZone timeZoneWithName:@"UTC"];

NSDate* date = [dateFormat dateFromString:dateString timeZone:&utcTimeZone];

STAssertEqualObjects([dateFormat stringFromDate:date timeZone:utcTimeZone], dateString, nil, nil);

The above test fails with

'2012-04-01T16:37:53Z' should be equal to '2012-04-01T15:37:53Z'

Not sure why the NSString returned by the stringFromDate:date is 1 hour later since both dates are using UTC.

boredzo commented 11 years ago

This appears to be fixed nowadays. I'm not sure when; my guess was [5665132], but reverting that commit didn't break the test, so it must have been some other fix that did it.

If you see it break again in current source (the test case should make it easy to detect in future), feel free to comment here and let me know.

qnoid commented 11 years ago

Thanks @boredzo :)