NSDateComponentsFormatter's stringFromDate(_, toDate:) returns nil
| Originator: | getaaron | ||
| Number: | rdar://19903541 | Date Originated: | 2/20/2015 |
| Status: | Open | Resolved: | |
| Product: | iOS SDK | Product Version: | Xcode 6.3 (6D520o) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary: NSDateComponentsFormatter's stringFromDate(_, toDate:) returns nil when passed two dates Steps to Reproduce: let formatter = NSDateComponentsFormatter() let referenceDate = NSDate(timeIntervalSinceReferenceDate: 0) let intervalDate = NSDate(timeInterval: 3628810, sinceDate: referenceDate) let string = formatter.stringFromDate(referenceDate, toDate: intervalDate) Expected Results: I'm expecting a string like "6w 0:00:10" to be returned. Actual Results: nil is returned. Version: Reproduces in both Xcode 6.1.1 (6A2008a) and Xcode 6.3 (6D520o) Notes: Different results depending on the value assigned to formatter.allowedUnits. If `.DayCalendarUnit | .HourCalendarUnit | .MinuteCalendarUnit | .SecondCalendarUnit` is assigned, it works as expected. If `.WeekCalendarUnit` is assigned, I get the number 1. If `.YearCalendarUnit` or `.MonthCalendarUnit` is included, I get this error: "NSInvalidArgumentException", "Specifying positional units with gaps is ambiguous, and therefore unsupported"
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
Additional Notes
The documentation says "Default value is ... years | months | weeks | days | hours | minutes | seconds if passed an NSTimeInterval or pair of NSDates." which it's clearly not doing.