0

I'm experiencing an error with NSPredicates in iOS 6.1 (simulator)

I have the following predicate:

    NSPredicate *eventsWithinPeriodePredicate = [NSPredicate predicateWithFormat:@"(startDate >= %@) AND (endDate <= %@)", startDate, endDate];

If i have an array with two objects with the following dates:

startDate = "2014-06-23T12:00:00.00000+0200";
endDate = "9999-12-31T23:59:59.00999+0100";

startDate = "2014-06-17T09:00:00.00000+0200";
endDate = "2014-06-17T11:00:00.00000+0200";

In iOS 7 (simulator and device) and iOS 5 (device) i get only the second event if i send 2014-06-17T00:00:00.00000 and 2014-06-17T23:59:00.00000

In iOS 6.1 running in simulator i get both events.

I don't have any iOS6 specific code involved here. Could this really be a bug? I don't have an iOS 6 device so i am unable to be sure whether this will affect the devices.

Lyck
  • 691
  • 1
  • 6
  • 18
  • Turns out iOS6.1 interprets the date 9999-12-31 to 1999-01-01 this is what messed up my dates, in turn messing up my NSPredicate. – Lyck Jun 23 '14 at 11:36

1 Answers1

0

Seems i ran into this problem with the dateformatter.

I made a workaround only for iOS 6. I haven't tested if this is a bug in all iOS 6 versions, but took all of them into account.

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0") && SYSTEM_VERSION_LESS_THAN(@"7.0"))
    {
        if([toDateTimeString hasPrefix:@"9999"])
        {
            endDate = [NSDate distantFuture];
        }
    }
Community
  • 1
  • 1
Lyck
  • 691
  • 1
  • 6
  • 18