Skip to content

Commit 0de4dc3

Browse files
authored
Fix spacing when using colonNotation option (#47)
1 parent 3862a59 commit 0de4dc3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ module.exports = (milliseconds, options = {}) => {
135135
}
136136

137137
if (typeof options.unitCount === 'number') {
138-
return result.slice(0, Math.max(options.unitCount, 1)).join(' ');
138+
const separator = options.colonNotation ? '' : ' ';
139+
return result.slice(0, Math.max(options.unitCount, 1)).join(separator);
139140
}
140141

141142
return options.colonNotation ? result.join('') : result.join(' ');

test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ test('`colonNotation` option', t => {
255255
t.is(prettyMilliseconds(1000 * 90, {colonNotation: true, secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true}), '1:30.000');
256256
t.is(prettyMilliseconds(1000 * 60 * 10, {colonNotation: true, secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true}), '10:00.000');
257257

258+
// Together with `unitCount`
259+
t.is(prettyMilliseconds(1000 * 90, {colonNotation: true, secondsDecimalDigits: 0, unitCount: 1}), '1');
260+
t.is(prettyMilliseconds(1000 * 90, {colonNotation: true, secondsDecimalDigits: 0, unitCount: 2}), '1:30');
261+
t.is(prettyMilliseconds(1000 * 60 * 90, {colonNotation: true, secondsDecimalDigits: 0, unitCount: 3}), '1:30:00');
262+
t.is(prettyMilliseconds(95543, {colonNotation: true, secondsDecimalDigits: 1, unitCount: 1}), '1');
263+
t.is(prettyMilliseconds(95543, {colonNotation: true, secondsDecimalDigits: 1, unitCount: 2}), '1:35.6');
264+
t.is(prettyMilliseconds(95543 + (1000 * 60 * 60), {colonNotation: true, secondsDecimalDigits: 1, unitCount: 3}), '1:01:35.6');
265+
258266
// Make sure incompatible options fall back to `colonNotation`
259267
t.is(prettyMilliseconds((1000 * 60 * 59) + (1000 * 59) + 543, {colonNotation: true, formatSubMilliseconds: true}), '59:59.6');
260268
t.is(prettyMilliseconds((1000 * 60 * 59) + (1000 * 59) + 543, {colonNotation: true, separateMilliseconds: true}), '59:59.6');

0 commit comments

Comments
 (0)