GitXplorerGitXplorer
u

format-duration

public
58 stars
14 forks
0 issues

Commits

List of commits on branch main.
Unverified
227770fb7c2cb2f7f95370a3e9ee57079a9af433

chore: fixpack

uungoldman committed 5 months ago
Verified
450cc12c9ca154805ba64a3c43275008e78b0f14

chore(deps): bump actions/setup-node from 3 to 4 (#22)

ddependabot[bot] committed a year ago
Verified
d69e2efee3c2a12934720687639bc407a81b93aa

chore(deps): bump actions/checkout from 3 to 4 (#21)

ddependabot[bot] committed a year ago
Unverified
15dcad129b20ff1854d1682c70aaded73730a194

3.0.2

uungoldman committed 2 years ago
Unverified
e32233da43e727baad442f301c17a329d525c97e

docs(changelog): 3.0.2

uungoldman committed 2 years ago
Verified
b10e481272eb9cf9187bbd150c1f621b58afe7d5

Move FormatDurationOptions under namespace formatDuration (#20)

ssebinemeth committed 2 years ago

README

The README file for this repository.
stopwatch

format-duration

Convert a number in milliseconds to a standard duration string.

npm build downloads

Install

npm install format-duration

Usage

const format = require('format-duration')

// anything under a second is rounded down to zero
format(999) // '0:00'

// 1000 milliseconds is a second
format(1000) // '0:01'

// 1999 rounds down to 0:01
format(1000 * 2 - 1) // '0:01'

// 60 seconds is a minute
format(1000 * 60) // '1:00'

// 59 seconds looks like this
format(1000 * 60 - 1) // '0:59'

// 60 minutes is an hour
format(1000 * 60 * 60) // '1:00:00'

// 59 minutes and 59 seconds looks like this
format(1000 * 60 * 60 - 1) // '59:59'

// 24 hours is a day
format(1000 * 60 * 60 * 24) // '1:00:00:00'

// 23 hours, 59 minutes, and 59 seconds looks like this
format(1000 * 60 * 60 * 24 - 1) // '23:59:59'

// 365 days looks like this (not bothering with years)
format(1000 * 60 * 60 * 24 * 365) // '365:00:00:00'

// anything under a second is rounded down to zero
format(-999) // '0:00'

// 1000 milliseconds is a second
format(-1000) // '-0:01'

// 365 days looks like this (not bothering with years)
format(-1000 * 60 * 60 * 24 * 365) // '-365:00:00:00'

// with `leading` option, formatting looks like this
format(1000 * 60, { leading: true }) // '01:00'
format(1000 * 60 - 1, { leading: true }) // '00:59'
format(1000 * 60 * 60, { leading: true }) // '01:00:00'

// with `ms` option, formatting looks like this
format(999, { ms: true }) // '0:00.999'
format(1000 * 60, { ms: true }) // '1:00.000'
format(1000 * 60 * 60 * 24 - 1, { ms: true }) // '23:59:59.999'

Contributing

Contributions welcome! Please read the contributing guidelines first.

License

ISC

Stopwatch image is from emojidex.