NSDateFormatter fails to convert string to date when string is a date 24 hours after a winter to summer timezone transition
| Originator: | dave.evans55 | ||
| Number: | rdar://18199442 | Date Originated: | 2-sep-2014 |
| Status: | open | Resolved: | no |
| Product: | OS X | Product Version: | l10.11 and earlier |
| Classification: | Reproducible: | yes |
n the Europe/London timezone, for some years and times 24 hours after t winter to summer time transition, NSDateFormatter fails to convert a valid date string to an NSDate
source code follows the test results
Expected Results:
I expect to see a non-nil NSDate
Actual Results:
======= Begin Test
Comment: This should work - just an ordinary date
date to convert: 7aug14 20:12
result: 2014-08-07 19:12:00 +0000
======= Begin Test
Comment: This should return nil -daylight saving transition
date to convert: 27mar94 01:00
result: (null)
======= Begin Test
Comment: This should work (but fails)- 24 hours after transition
date to convert: 28mar94 01:00
result: (null)
======= Begin Test
Comment: This should work (and it does) - 24 hours after another transition
date to convert: 31mar14 01:00
result: 2014-03-31 00:00:00 +0000
Source code:
================ cut here ===================
// Command line tool to illustrate NSDateFormater dateFromString bug
// when processing dates 24 hours after a transition from
// standard time to daylight saving time.
// Author: David Evans
// Email: dave.evans55@googlemail.com
// Date: Tue 2 September 2014
// Compiled without ARC
#include <Foundation/Foundation.h>
void testone(NSString * comment, NSString * aDate){
NSDateFormatter *df = [[NSDateFormatter alloc ] init];
NSLocale *enUSPOSIXLocale = [[NSLocale alloc]
initWithLocaleIdentifier:@"en_US_POSIX"];
[df setLocale:enUSPOSIXLocale];
[df setDateFormat: @"ddMMMyy HH:mm" ];
[df setTimeZone: [NSTimeZone timeZoneWithName:@"Europe/London"]];
NSLog(@"======= Begin Test");
NSLog(@"Comment: %@", comment);
NSLog(@"date to convert: %@", aDate);
NSLog(@"result: %@", [[df dateFromString:aDate] description]);
[enUSPOSIXLocale release];
[df release];
return;
}
int main(){
@autoreleasepool {
testone(@"This should work - just an ordinary date",
@"7aug14 20:12");
testone(@"This should return nil -daylight saving transition",
@"27mar94 01:00");
testone(@"This should work (but fails)- 24 hours after transition",
@"28mar94 01:00");
testone(@"This should work (and it does) - 24 hours after another transition",
@"31mar14 01:00");
}
}
============== cut here ==============
Comments
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!