Closed mickeyvip closed 7 years ago
Could this just proxy to toFixed
?
(0.499).toFixed(1) // => "0.5"
(0.499).toFixed(2) // => "0.50"
(0.499).toFixed(3) // => "0.499"
If I proxy it to .toFixed()
I would lose the time units.
If you'd like to submit a PR, feel free!
That would be awesome :)
Perhaps round
param could take a function instead of boolean value. This would be far more flexible as I need for example to cut off seconds, not to round them.
@topr Agreed. One thing that makes this tricky is how rounding affects other numbers. For example, what happens if you do something like this?
humanizeDuration(123456, {
round: function () {
return 0
}
})
Would it be an issue? Not sure but I guess result should then be the same as if 0 would be passed in instead of 123456, shouldn't it?
I don't think the lib should care or prevent such a misuse. If someone passes a custom impl then it's his responsibility to make it right.
I was mostly thinking about use cases like humanizeDuration(123456, { round: Math.floor })
On 2 Feb 2017 22:58, "Evan Hahn" notifications@github.com wrote:
@topr https://github.com/topr Agreed. One thing that makes this tricky is how rounding affects other numbers. For example, what happens if you do something like this?
humanizeDuration(123456, { round: function () { return 0 } })
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/EvanHahn/HumanizeDuration.js/issues/73#issuecomment-277111919, or mute the thread https://github.com/notifications/unsubscribe-auth/AA1TIpAvF0-3Xsd6UjHiXpK98VDnSJv2ks5rYl-igaJpZM4FckB4 .
What if you're trying to humanize the largest 2 units and then you choose to round down? For example, your result might start like this before you round and do your cutoff:
2 weeks, 6 days, 23 hours, 59 minutes
Depending on how you round, the results can be different. If you round up, you could get "3 weeks". If you round down, you should get "2 weeks, 6 days". These rounding issues can cascade, which is why it's tricky (but not impossible).
+1. This would be nice.
Do it.
Lots of people seem to want this feature and things around it. I want to do it but I'm worried it gets really hairy with lost of corner cases. What do people think about my comment from February?
{
units: ['d','m','s'],
unitsConfig: {
m: {
label: 'min', // languages
measure: 30, // unitMeasures
round: value => 1
}
}
}
This library is in maintenance mode, so I won't be adding new features, sadly. I'm going to close this issue. See #120 for more.
Use pretty-ms instead.
Hi and thank you!
I think it would be a great addition to have be able to round to a specific number of decimal places:
now:
would be nice: