closure-library
closure-library copied to clipboard
Allow goog.date.relative.format to format relative dates with second precision
In our application it would be helpful to get a relative date format (edit: from goog.date.relative.format) with second precision, e.g. "in 5 seconds", "35 seconds ago", e.t.c.
Is it likely that a PR for this functionality would be accepted? I'm happy to put it together if the idea is acceptable. One thing I'm not too sure about is backwards compatibility. Is it acceptable for the return value of times less than a minute from now to change from (for example) "1 minute ago" to "37 seconds ago"?
@fabalbon Don't we already have something like this?
@joeltine We have closure/goog/date/relative.js, but it has minute precision. If I'm not mistaken, what @danielcompton is proposing is to add second precision to this API. Regarding backwards compatibility I think it might be a problem because users might be expecting minute precision so I wouldn't change the default behavior.
If I'm not mistaken, what @danielcompton is proposing is to add second precision to this API.
Yep, that's correct.
Regarding backwards compatibility I think it might be a problem because users might be expecting minute precision so I wouldn't change the default behavior.
I can see two possibilities to preserve backwards compatibility:
- Provide an extra parameter to
goog.date.relative{format, formatDay, formatPast, ...}, as to be consistent, all of the relative formatters should be able to return the same format. - Make
setTimeDeltaFormattera publicly usable function and let users override it. However this doesn't feel like a very good approach. - Add another function to toggle if relative date formats include seconds.
I'm happy to put together a PR with some guidance on which option (or another) would be preferred. Not sure if I'm in love with any of the options. Instantiating and using a formatter feels like a better option. There's a comment from 2013 suggesting that this be moved to goog.i18n.DateTimeFormat once a new version of CLDR comes out.