NSDataDetector is returning wrong date for languages other than English

370 Views Asked by At

So I am using NSDataDetector to get date from different languages. It returns correct date for English but for other language the returned dates are current date. Here are the codes.

NSString *dateEn = @"Added on Wednesday, February 4, 2015 5:58:18 PM";
NSString *dateStringRussian = @"Добавлено: суббота, 26 декабря 2015 г. в 0:16:57";
NSString *dateStringPortuguese = @"Adicionado: sábado, 26 de dezembro de 2015 11:39:53";

__block NSDate *dateFromDetector;
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeDate error:nil];
[detector enumerateMatchesInString:dateStringPortuguese options:kNilOptions range:NSMakeRange(0, [dateStringPortuguese length]) usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
    dateFromDetector = result.date;    
}];

NSLog(@"date is %@", dateFromDetector);

output Portuguese: 2016-02-25 22:04:18.530 DateDetector[1681:56498] date is 2016-02-25 18:09:53 +0000

output Russian: 2016-02-25 22:14:03.416 DateDetector[1725:60212] date is 2016-02-24 18:46:57 +0000

output English: 2016-02-25 22:12:13.123 DateDetector[1712:59498] date is 2015-02-04 12:28:18 +0000

What is wrong here?

0

There are 0 best solutions below