Nat! bio photo

Nat!

Senior Mull.

Twitter RSS

Github

iOS NSTimeZone/NSCalendar Semi-Final Germany vs Brazil

A somewhat obscure and nasty bug in iOS:


- (void) testGermany
{
   NSDate            *date;
   NSDateFormatter   *formatter;


   formatter = [[NSDateFormatter new] autorelease];
   [formatter setDateFormat:@"yyyy-MM-dd"];

   //  Start DST: Sonntag, 30. März 2014
   // 1 hour forward

   date = [formatter dateFromString:@"2014-3-31"];
   NSParameterAssert( date);
   date = [formatter dateFromString:@"2014-3-30"];
   NSParameterAssert( date);
}


- (void) testBrazil
{
   NSDate            *date;
   NSDateFormatter   *formatter;


   formatter = [[NSDateFormatter new] autorelease];
   [formatter setDateFormat:@"yyyy-MM-dd"];

   // Start DST: Sonntag, 19. Oktober 2014
   // 1 hour forward

   date = [formatter dateFromString:@"2014-10-20"];
   NSParameterAssert( date);
   date = [formatter dateFromString:@"2014-10-19"];
   NSParameterAssert( date);  // will crash when played in Brasilia-Normalzeit
}


- (void) viewDidLoad
{
   [super viewDidLoad];

   [self testGermany];
   [self testBrazil];
}



1 Comment

A photo of Helge Heß

From: Helge Heß

I bet it is a leftover / side effect of this: http://en.wikipedia.org/wiki/Daylight_saving_time_in_Brazil

"Before 2008, there were no fixed start and end dates for summer time, nor which states should or should not follow it; they were decided every year by one or more decrees, sometimes published very close to their start date"

Post a comment

All comments are held for moderation; basic HTML formatting accepted.

Name:
E-mail: (not published)
Website: