diff --git a/index.d.ts b/index.d.ts index 6dd4591..f8401e1 100644 --- a/index.d.ts +++ b/index.d.ts @@ -26,7 +26,7 @@ declare namespace prettyMilliseconds { readonly keepDecimalsOnWholeSeconds?: boolean; /** - Only show the first unit: `1h 10m` → `~1h`. + Only show the first unit: `1h 10m` → `1h`. Also ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`. @@ -99,7 +99,7 @@ prettyMilliseconds(133); // `compact` option prettyMilliseconds(1337, {compact: true}); -//=> '~1s' +//=> '1s' // `verbose` option prettyMilliseconds(1335669000, {verbose: true}); diff --git a/index.js b/index.js index 4e12f17..32a4084 100644 --- a/index.js +++ b/index.js @@ -113,7 +113,7 @@ module.exports = (milliseconds, options = {}) => { } if (options.compact) { - return '~' + result[0]; + return result[0]; } if (typeof options.unitCount === 'number') { diff --git a/readme.md b/readme.md index cbef029..f6d8cce 100644 --- a/readme.md +++ b/readme.md @@ -24,7 +24,7 @@ prettyMilliseconds(133); // `compact` option prettyMilliseconds(1337, {compact: true}); -//=> '~1s' +//=> '1s' // `verbose` option prettyMilliseconds(1335669000, {verbose: true}); @@ -87,7 +87,7 @@ Useful when you are showing a number of seconds spent on an operation and don't Type: `boolean`\ Default: `false` -Only show the first unit: `1h 10m` → `~1h`. +Only show the first unit: `1h 10m` → `1h`. Also ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`. diff --git a/test.js b/test.js index c5653ba..a9f65ec 100644 --- a/test.js +++ b/test.js @@ -19,10 +19,10 @@ test('prettify milliseconds', t => { }); test('have a compact option', t => { - t.is(prettyMilliseconds(1000 + 4, {compact: true}), '~1s'); - t.is(prettyMilliseconds(1000 * 60 * 60 * 999, {compact: true}), '~41d'); - t.is(prettyMilliseconds(1000 * 60 * 60 * 24 * 465, {compact: true}), '~1y'); - t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {compact: true}), '~1y'); + t.is(prettyMilliseconds(1000 + 4, {compact: true}), '1s'); + t.is(prettyMilliseconds(1000 * 60 * 60 * 999, {compact: true}), '41d'); + t.is(prettyMilliseconds(1000 * 60 * 60 * 24 * 465, {compact: true}), '1y'); + t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {compact: true}), '1y'); }); test('have a unitCount option', t => { @@ -97,19 +97,19 @@ test('work with verbose and compact options', t => { compact: true }); - t.is(fn(1000), '~1 second'); - t.is(fn(1000 + 400), '~1 second'); - t.is(fn((1000 * 2) + 400), '~2 seconds'); - t.is(fn(1000 * 5), '~5 seconds'); - t.is(fn(1000 * 55), '~55 seconds'); - t.is(fn(1000 * 67), '~1 minute'); - t.is(fn(1000 * 60 * 5), '~5 minutes'); - t.is(fn(1000 * 60 * 67), '~1 hour'); - t.is(fn(1000 * 60 * 60 * 12), '~12 hours'); - t.is(fn(1000 * 60 * 60 * 40), '~1 day'); - t.is(fn(1000 * 60 * 60 * 999), '~41 days'); - t.is(fn(1000 * 60 * 60 * 24 * 465), '~1 year'); - t.is(fn(1000 * 60 * 67 * 24 * 750), '~2 years'); + t.is(fn(1000), '1 second'); + t.is(fn(1000 + 400), '1 second'); + t.is(fn((1000 * 2) + 400), '2 seconds'); + t.is(fn(1000 * 5), '5 seconds'); + t.is(fn(1000 * 55), '55 seconds'); + t.is(fn(1000 * 67), '1 minute'); + t.is(fn(1000 * 60 * 5), '5 minutes'); + t.is(fn(1000 * 60 * 67), '1 hour'); + t.is(fn(1000 * 60 * 60 * 12), '12 hours'); + t.is(fn(1000 * 60 * 60 * 40), '1 day'); + t.is(fn(1000 * 60 * 60 * 999), '41 days'); + t.is(fn(1000 * 60 * 60 * 24 * 465), '1 year'); + t.is(fn(1000 * 60 * 67 * 24 * 750), '2 years'); }); test('work with verbose and unitCount options', t => { @@ -173,9 +173,9 @@ test('work with verbose and formatSubMilliseconds options', t => { }); test('compact option overrides unitCount option', t => { - t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 1}), '~1 year'); - t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 2}), '~1 year'); - t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 3}), '~1 year'); + t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 1}), '1 year'); + t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 2}), '1 year'); + t.is(prettyMilliseconds(1000 * 60 * 67 * 24 * 465, {verbose: true, compact: true, unitCount: 3}), '1 year'); }); test('work with separateMilliseconds and formatSubMilliseconds options', t => {