NSDateFormatter conversion off by 7 minutes 2 seconds for dates before Nov 18, 1883

Originator:dhendrix
Number:rdar://11264351 Date Originated:4/17/2012
Status:Open Resolved:
Product:Mac OS X SDK Product Version:10.7
Classification: Reproducible:Always
 
17-Apr-2012 09:50 AM David Hendrix:
Summary: Using NSDateFormatter's stringFromDate: to convert dates/times prior to November 18, 1883 results in time values that appear off by 7 minutes, 2 seconds.

Steps to Reproduce:
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setLocale:[NSLocale currentLocale]];
    [df setDateStyle:NSDateFormatterFullStyle];
    [df setTimeStyle:NSDateFormatterFullStyle];

    NSDate *testDate = [[NSDate alloc] initWithString:@"1883-11-17 12:00:00 -0800"];
    NSLog(@"Nov 17, 1883, 12:00:00 - NSDate description:             %@", testDate);
    NSLog(@"Nov 17, 1883, 12:00:00 - NSDateFormatter stringFromDate: %@\n", [df stringFromDate:testDate]);

Expected Results:

2012-04-17 09:34:31.256 Time Check[8500:403] Nov 17, 1883, 12:00:00 - NSDate description:             1883-11-17 20:00:00 +0000
2012-04-17 09:34:31.256 Time Check[8500:403] Nov 17, 1883, 12:00:00 - NSDateFormatter stringFromDate: Saturday, November 17, 1883 12:00:00 PM GMT-08:00:00

Actual Results:

2012-04-17 09:34:31.256 Time Check[8500:403] Nov 17, 1883, 12:00:00 - NSDate description:             1883-11-17 20:00:00 +0000
2012-04-17 09:34:31.256 Time Check[8500:403] Nov 17, 1883, 12:00:00 - NSDateFormatter stringFromDate: Saturday, November 17, 1883 12:07:02 PM GMT-07:52:58

Comments

Not a bug

Actually, this is not a bug but a feature. On November 18, 1883, US established time zones, see http://www.wired.com/thisdayintech/2010/11/1118railroad-time-zones/ The NSDateFormatter seems to take this into account, and computes differently the offset from Greenwich. This offset appears to be obtained from America/LosAngeles time zone (on your computer), and since Los Angeles has geo-location: 34.0522° N, 118.2428° W , the longitude is proportional to difference to 120 ° W, the official time zone longitude for Pacific, according to rail load-time-zones. This difference turns out to be 7 minutes 1.7 (2) seconds shorter from full hour. If you add 12:07:02-(0800-07:52:58) you get the same time as expected but in different format. If you compute the time difference between Nov17, 1883, noon and Nov 18, 1883, noon, you will get exactly 86400 seconds.

Igor Pavlin, Science for iPad, LLC

By igor.pavlin at June 21, 2012, 8:13 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!