d3/d3-time-format

Ago?

curran opened this issue · 4 comments

I was just evaluating various "time ago" libraries, such as https://github.com/hustcc/timeago.js and https://github.com/nmn/react-timeago , and it occurred to me that a formatter using the ago format would probably be straightforward to construct using d3-time-format.

Might it be of interest to include an ago formatting method as part of d3-time-format?

Returning an update interval in ms would also be a useful counterpart, for updating the string.

I’m currently considering the long-term plan for this library.

JavaScript’s native support for localized date and time formatting has improved dramatically since D3 was first created (and pv.Format.time in Protovis before that). In particular, the fact that date.toLocaleString automatically uses the browser’s current locale is such a huge improvement (less en-US-centric) that I feel promoting d3-time-format’s continued use is harmful.

https://beta.observablehq.com/@mbostock/date-formatting

There is a standard for relative time format, Intl.RelativeTimeFormat:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RelativeTimeFormat

It hasn’t made it to Edge and Safari yet, but Edge will eventually be Chromium, and Safari will hopefully come around. I expect therefore it would be better to encourage adoption of the standard and perhaps offer a polyfill than to compete with the proposed standard.

Excellent! Thank you for putting some time into this.

Thanks for the reference to https://github.com/catamphetamine/relative-time-format from your notebook, I had not seen that one.

I have no plans to expand the scope of this library to cover relative time formatting.