I'm testing some values for a date format ("dd-MM-yyyy"
) and there's a special case that I can't explain:
var datef = NSDateFormatter()
datef.dateFormat = "dd-MM-yyyy";
var date_a = "02-01-1990"
var date_b = "01-01-1990"
var date_f_a = datef.dateFromString(date_a);
var date_f_b = datef.dateFromString(date_b);
data_f_a
returns Jan 2, 1990, 12:00 AM, but date_f_b
returns nil. Any other date will return the expected value, except for January 1st, 1990.
If I add datef.lenient = true
date_f_b is no longer nil, but I shouldn't need to do that. Why is it an invalid date?
EDIT 1:
It happens the same if I use DateFormatter()
:
EDIT 2: Xcode version: 8.1