EvanHahn / HumanizeDuration.js

361000 becomes "6 minutes, 1 second"
https://evanhahn.github.io/HumanizeDuration.js/
The Unlicense
1.65k stars 175 forks source link

Return the largest two units #46

Closed tazmaniax closed 9 years ago

tazmaniax commented 9 years ago

Hello,

Is there a setting to return just the largest two units with a bottom unit limit so that the string is not too long or too granular? For example 3 weeks and 1 day 3 days and two hours 4 hours and 20 minutes 5 minutes

Something similar is described here, http://stackoverflow.com/a/14157442/1030246

cheers, Chris

EvanHahn commented 9 years ago

Short answer: not yet! What would you want that API to look like?

tazmaniax commented 9 years ago

Maybe config setting like 'limitUnits', e.g. humanizeDuration(150000, { limitUnits: 2 }), to limit the number of units displayed starting from the least granular with the default being undefined so display all units.

The other option I mentioned could be 'smallestUnit', e.g humanizeDuration(150000, { smallestUnit: "minutes" }), to limit the smallest unit displayed with the default being seconds. This would save having to specify all of the units if you wanted a subset by just specifying the smallest one.

How does that sound? And thanks for the great library, very useful!!

EvanHahn commented 9 years ago

Could you imagine something even MORE flexible? Like...give me the smallest 2 units but don't ever give me hours? Something like that?

Sorry I'm slow to respond!

On Mon, Apr 6, 2015 at 2:44 PM, Chris Webb notifications@github.com wrote:

Maybe config setting like 'limitUnits', e.g. humanizeDuration(150000, { limitUnits: 2 }), to limit the number of units displayed starting from the least granular with the default being undefined so display all units.

The other option I mentioned could be 'smallestUnit', e.g humanizeDuration(150000, { smallestUnit: "minutes" }), to limit the smallest unit displayed with the default being seconds. This would save having to specify all of the units if you wanted a subset by just specifying the smallest one.

How does that sound?

— Reply to this email directly or view it on GitHub https://github.com/EvanHahn/HumanizeDuration.js/issues/46#issuecomment-90214007 .

tazmaniax commented 9 years ago

I'm not sure what the use case would be for "give me the smallest 2 units but don't ever give me hours" - in terms of duration displaying smaller units without the larger units first if present is not meaningful. The only use case I can think of is "keeping the duration string arbitrarily short", so limiting the granularity by starting with the largest unit(s) and then progressively increasing the granularity as the duration gets less. e.g. 1 week then 6 days then 8 hours then 15 minutes, etc.

EvanHahn commented 9 years ago

I'm adding this to the 3.0 milestone.

tazmaniax commented 9 years ago

Great, do you have a rough ETA for v3 release?

EvanHahn commented 9 years ago

I'd estimate within the week. There's a lot of localization stuff I'm running into—sorry!

tazmaniax commented 9 years ago

Please don't apologise :) I feel bad I can't contribute more. A big thanks to you!

EvanHahn commented 9 years ago

This is in the 3.0.0 branch and will be merged very soon.