Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`
by sindresorhusJavaScript
Last 12 weeks · 0 commits
4 of 6 standards met
I have the following situation: 1. I have and 2. I display , , and to the end-user 3. The result looks wrong because (conceptually) does not equal (due to rounding) Example: Wondering how you'd suggest to handle this? One idea: expose the rounded numeric value alongside the string (e.g. a -style API, or output), so callers can compute the delta from the values as displayed instead of from the raw inputs. Alternatively, an option to format a set of related values consistently (shared unit and precision). The same issue happens in .
@sindresorhus Would you accept a PR that takes an option to keep the decimals on whole numbers? I'm using this library for a progress indicator thingy which keeps updating the time spent every ~60ms or so, and it keeps flickering in the terminal when it hits a whole number - I'd prefer if it just kept the fixed length as specified. @sindresorhus For the same reason, I would find it preferable if sub-seconds could be output as seconds. I.e. -> . Right now I'm wrapping and adding the logic myself, but does it qualify for an option to be included in the library? _Originally posted by @ulken in https://github.com/sindresorhus/pretty-ms/issues/20#issuecomment-1825457807_
Repository: sindresorhus/pretty-ms. Description: Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s` Stars: 1212, Forks: 66. Primary language: JavaScript. Languages: JavaScript (96.2%), TypeScript (3.8%). License: MIT. Topics: humanize, milliseconds, npm-package. Latest release: v9.3.0 (9mo ago). Open PRs: 0, open issues: 0. Last activity: 3h ago. Community health: 85%. Top contributors: sindresorhus, fisker, icyflame, villebro, arnellebalane, Richienb, kevva, ehmicky, OyuNet, Rich-Harris and others.