objective c - Getting screwy results from NSDateComponentsFormatter -
i learned new-to-ios8 class nsdatecomponentsformatter. lets generate time strings time-spans rather dates. pretty cool. decided tinker it, , wrote test code creates various time-spans , logs output. here's code (english , french output) nscalendar *gregorian = [[nscalendar alloc] initwithcalendaridentifier:nscalendaridentifiergregorian]; nsdatecomponentsformatter* formatter = [[nsdatecomponentsformatter alloc] init]; formatter.unitsstyle = nsdatecomponentsformatterunitsstylefull; formatter.calendar = gregorian; formatter.allowedunits = nscalendarunityear + nscalendarunitmonth + nscalendarunitday; nsdatecomponents *components = [[nsdatecomponents alloc] init]; (int years = 1; years <= 10; years++) { int days = arc4random_uniform(10); components.year = years; components.month = 3; components.day = days; nsstring* outputstring = [formatter stringfromdatecomponents: components]; nslog(@"for %02d years %02d days, date components ...