sproutcore/sproutcore — pull request #867 by krotscheck (2012-11-15 21:14:40+00:00)
Title: Adds a new DateTime formatting option for human readable durations

This pull request adds one new calculated property "elapsed", and two new string formatting options: %E and %e.

The elapsed property returns the number of milliseconds until (-), or since (+), the date stored in the dateTime object. This simplifies time-based calculations such as expiring tokens, cache refreshes, and similar logic.

The %E and %e formatting options together allow the creation of "accurate-ish" representations of elapsed time by seconds, minutes, hours, days, weeks, months, and years. For example "10 minutes ago" could represent an elapsed time of 10 minutes and 32 seconds. "Next Year" represents something that's 400 days from today. The formatting option does NOT include an automatic refresh mechanism- that is left to the application engineer, as requirements on views may differ.

Unit Tests and localization strings provided. The implementation is twofold: "Elapsed" is in datetime/core, as that merely calculates an integer. The string formatter however is split into two parts, one stubbed out portion in datetime/core (since datetime must be loaded before localization), and a mixin override in datetime/localized.