4 ms·
From the proposal [1]: > It is the caller's responsibility to handle cut-off logic such as deciding between displaying "in 7 days" or "in 1 week". This API doe
by wongarsu 8y ago
From the proposal [1]:
> It is the caller's responsibility to handle cut-off logic such as deciding between displaying "in 7 days" or "in 1 week". This API does not support relative dates involving compound units. e.g "in 5 days and 4 hours".
Specifying the locale is optional, and you can specify a list that will be matched against the user agent's preferences.
1: https://github.com/tc39/proposal-intl-relative-time#api https://github.com/tc39/proposal-intl-relative-time#api
- masklinn 8y ago> It is the caller's responsibility to handle cut-off logic such as deciding between displaying "in 7 days" or "in 1 week". That seems like it'd make the API quite significantly less convenient: it becomes unusable on its own and pretty much has to be wrapped in a helper of some sort.
- ithkuil 8y agoBut the helper can be very thin and doesn't have to ship with massive locale data
- jypepin 8y agoadding some simple mapping to decide what to display would not add much size to this lib.
- wongarsu 8y agoOn the other hand there is no obviously right way, and you really need context to decide on the right way to display a duration of 20 days. This way you can write a fairly small wrapper that makes the interesting decisions and leaves the grunt work to the API
- jypepin 8y agoIn a lot of cases, you don't really. Most cases it is pretty easy to guess what you'd want to show. I'd the say the case where you really want to choose IS the hedge case. Moment.js does it, and I never felt like it wasn't what I wanted: https://momentjs.com/docs/#/displaying/fromnow/ https://momentjs.com/docs/#/displaying/fromnow/