Skip to content

Instantly share code, notes, and snippets.

@zbowling
Created May 1, 2012 05:05
Show Gist options
  • Save zbowling/2565244 to your computer and use it in GitHub Desktop.
Save zbowling/2565244 to your computer and use it in GitHub Desktop.
nasty NSDateFormatter parsing bug.
static NSLocale *enUSLocale = nil;
static NSDateFormatter *timestampFormatter = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
enUSLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
timestampFormatter = [[NSDateFormatter alloc] init];
[timestampFormatter setLocale:enUSLocale];
[timestampFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.S"];
[timestampFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
});
(gdb) po dateString
2012-05-01 00:53:46.999976
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 00:53:46.9999760"]
Can't print the description of a NIL object.
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 00:53:46.0999760"]
2012-05-01 00:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 00:53:46.8999760"]
2012-05-01 00:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 00:53:46.9"]
2012-05-01 00:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 00:53:46.999"]
2012-05-01 00:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 00:53:46.9999"]
Can't print the description of a NIL object.
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.9999"]
Can't print the description of a NIL object.
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.9998"]
Can't print the description of a NIL object.
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.9991"]
2012-05-01 01:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.9993"]
2012-05-01 01:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.9994"]
2012-05-01 01:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.9995"]
Can't print the description of a NIL object.
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.99945"]
2012-05-01 01:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.99949"]
2012-05-01 01:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.99950"]
Can't print the description of a NIL object.
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.99951"]
Can't print the description of a NIL object.
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.9994999"]
2012-05-01 01:53:46 +0000
(gdb) po [timestampFormatter dateFromString:@"2012-05-01 01:53:46.9994999999999"]
2012-05-01 01:53:46 +0000
(gdb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment