NSCalendar addition truncates to microseconds
Originator: | boredzo | ||
Number: | rdar://6685322 | Date Originated: | 2009-03-16T05:24-0700 |
Status: | Open | Resolved: | |
Product: | Mac OS X | Product Version: | 10.5.6/9G55 |
Classification: | Other Bug | Reproducible: | Always |
Summary: NSCalendar's dateByAddingComponents:toDate:options: method returns a date that is a whole number of milliseconds since the Reference Date, regardless of any fraction of milliseconds present in the original date. Steps to Reproduce: 1. Create a date whose number of seconds since the Reference Date includes a fraction of a millisecond (i.e., the fractional part of the interval contains non-zero digits after 0.001). 2. Create a Gregorian calendar. 3. Create an NSDateComponents instance. 4. Set the day component to -1. 5. Ask the calendar to add the components to the original date (thereby subtracting one day). 6. Use timeIntervalSinceDate: to subtract the original date from the computed date. Expected Results: Since the components in NSDateComponents are all of integral types, the calendar returns a computed date whose interval from the Reference Date has the same fraction of milliseconds as the original date (within the limits of floating-point arithmetic). As such, the interval between the two dates is exactly (or as close to exactly as possible) 86400.0000. Actual Results: NSCalendar truncates the computed date to a whole number of milliseconds. As such, the interval between the two dates is almost always greater than 86400.0000. Regression: Unknown. Notes: I'm including a test app. Here's its output on my system: Starting date: 258879920.079869 One day earlier: 258793520.079000 Interval between: 86400.000869
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!