I'm using 'moment' library. I have a duration in minutes, and I want it to be humanized.
For example:
const totalMinutes = 124;
console.log(moment.duration(totalMinutes, 'minutes').humanize()); // prints 2 hours
but that's not what I want, I want it to be:
124 => 2 hours, 4 minutes
34 => 34 minutes // no hours
725 => 12 hours, 5 minutes
I don't care about days or seconds.
I know that I can somehow extract the hours and minutes and join them to make the final string, but I feel there is a shorter way at least using the library itself. Not to mention that I want the text to be localized in other languages, which moment library itself support.
Unfortunately, it seems that Moment JS library doesn't have this out of the box, and I had to use another library.
Here is the solution:
import humanizeDuration from "humanize-duration";
console.log(humanizeDuration(658 * 60 * 1000, { language: 'en'}));
// prints 10 hours, 58 minutes
console.log(humanizeDuration(55 * 60 * 1000, { language: 'en'}));
// prints 55 minutes
which is exactly what I want.