Closed sarim closed 10 years ago
What about this?
humanizeDuration(1234, { units: "hm" }) // => "XX hours, XX minutes"
yes that would work. But i think something like this,
var hD = humanizeDuration({
units: "hm",
delimiter: ","
});
hD(1234);
This way it'll be possible to add more user defined configurations.
So you'd prefer humanizeDuration to be more of a constructor object? I think I'd prefer for it to be a function, but I do like the idea of passing in many options.
Thoughts?
Umm,
humanizeDuration.setOptions({
units: "hm",
delimiter: ","
});
humanizeDuration(1234);
humanizeDuration.prototype.options = {
units: "hm",
delimiter: ","
};
humanizeDuration(1234);
Something like these?
What about this, as a subtle difference?
humanizeDuration(10000000) // 2 hours, 46 minutes, 40 seconds
humanizeDuration.setDefaults({
units: "hm",
delimiter: ", "
})
humanizeDuration(10000000) // 2 hours, 46 minutes
humanizeDuration(10000000, { delimiter: " and " }) // 2 hours and 46 minutes
humanizeDuration(10000000, { units: "s" }) // 10000 seconds
Ah, it like this. Options passed when calling the function would override the default options, nice :)
Working on it now...
@sarim I'm realizing an issue with changing the defaults; if two modules depend on HumanizeDuration and either of them change the defaults, that's bad. I'd really like to have an easy-to-use function that everyone can use, but I'd also like to make it customizable.
What do you think of this?
humanizeDuration(10000000) // 2 hours, 46 minutes, 40 seconds
humanizeDuration(10000000, { units: ["second"] }) // 10000 seconds
var h = humanizeDuration.humanizer({
units: ["hour", "minute"],
delimiter: " and "
})
h(10000000) // 2 hours, 46 minutes
Yeah, that looks much cleaner. :+1:
Finished this. This will go in the 2.0.0 release.
When calculating a big duration, i want to omit seconds and milliseconds.
Instead of
XX hours, XX minutes, XX seconds, XX milliseconds
,XX hours, XX minutes
looks more human readable.