EvanHahn / HumanizeDuration.js

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

Combining "largest" and "units" options can cause a unit to be skipped if zero #195

Closed skyegecko closed 3 years ago

skyegecko commented 3 years ago

I'm not entirely sure if this qualifies as a bug, but it wasn't what I expected.

Code:

var humanizeDuration = require("humanize-duration")
humanizeDuration(
  90005000, {
    largest: 3,
    units: ["d", "h", "m", "s"],
  }
)

Result:

"1 day, 1 hour, 5 seconds"

Expected:

"1 day, 1 hour, 0 minutes"

or alternatively

"1 day, 1 hour"

My interpretation of using the "largest" option in this way would be that once days > 0, seconds are no longer displayed. In the context of something like a duration that counts up live, it's somewhat incongruous to see a large number of days alongside a precise number of seconds, but only once an hour.

skyegecko commented 3 years ago

I've just realised that round does what I want. I should RTFM. Sorry for the noise!

EvanHahn commented 3 years ago

No worries!