Formatting of negative time intervals with NSDateComponentsFormatter

Originator:pete
Number:rdar://17436956 Date Originated:24-Jun-2014 06:03 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta2 (6A216f)
Classification:Enhancement Reproducible:Always
 
Summary:
Currently NSDateComponentsFormatter can append the localised "remaining" string to formatted components. It is a common requirement to format a time period in the past, for example "2 minutes ago"

Specifying a negative time period simply results in negative formatted values. It would be more useful if it returned a positive value with the localised "ago" string.

Steps to Reproduce:
Following code:

var formatter = NSDateComponentsFormatter()
formatter.unitsStyle = .Full
formatter.includesTimeRemainingPhrase = true

let formattedString = formatter.stringFromTimeInterval(-60)


Expected Results:
formattedString should contain the value "1 minute ago"

Actual Results:
formattedString contains the value "-1 minute remaining"

Comments

Response from Apple Developer Relations

The phrase "N minutes ago" does not actually specify the quantity of time, it specifies a moment in time described by an implicit reference to now and a quantity. Formatting moments in time, even if relative like this, would be more appropriate for NSDateFormatter. We can treat this as a request for improving relative date formatting on NSDateFormatter though, which would indeed be a great improvement.


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!