iOS17 Bug: NSCalendar compareDate:toDate:toUnitGranularity always return "same"

in iOS 17, I found the function [compareDate:toDate:toUnitGranularity] in NSCalendar always return “same” here is the code :


NSString *transformedFromDateStr = "2023-06-16";
NSString *transformedToDateStr = "2023-06-20";

NSDate *transformedFromDate = [NSDate dateWithString:transformedFromDateStr formatString:@"yyyy-MM-dd" timeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    NSDate *transformedToDate = [NSDate dateWithString:transformedToDateStr formatString:@"yyyy-MM-dd" timeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    
    NSCalendarUnit uint = NSCalendarUnitDay;
    NSCalendar *calendar = [NSCalendar currentCalendar];
    calendar.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
  
//the result  always return  true
    NSComparisonResult result = [calendar compareDate:transformedFromDate
                                               toDate:transformedToDate
                                    toUnitGranularity:uint];

now before iOS 17 is right, why this happened ?

I've noticed the same thing in our production app.

same bug with iOS 17, run with Xcode 14.2.

We are running into the same issue with the iOS 17 developer beta

iOS17 Bug: NSCalendar compareDate:toDate:toUnitGranularity always return "same"
 
 
Q