6 ms·
It's nice to see more libraries helping for this kind of things. But looking at the article it seems like the api needs you to pass the language and the unit (d
by jypepin 8y ago
It's nice to see more libraries helping for this kind of things. But looking at the article it seems like the api needs you to pass the language and the unit (days, hours, etc).
Does anyone know if there exists an option to not add one? For dynamic values this feature is pretty important. For example, when I post a tweet, I need to see "a few minutes ago" but look at the tweet later, "34563434 minutes ago" is not great.
If the developers have to start mapping time values to units (60: 'hours', '24': 'days', etc) that doesn't make the library very useful in a lot of cases.
- wongarsu 8y agoFrom 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/
- jontro 8y agoI expect you'll use a thin wrapper library around this. I think a lean api without a lot of business rules is the way to go