Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70a0a36

Browse files
committed
put back and test fractional second zero removal in auto case
1 parent e1d4e21 commit 70a0a36

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/lib/dates.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ function formatTime(x, tr) {
423423
*/
424424
var sec = Math.min(mod(x / ONESEC, 60), MAXSECONDS[tr]);
425425

426-
timeStr += ':' + (100 + sec).toFixed(tr).substr(1);
426+
timeStr += ':' + (
427+
(100 + sec).toFixed(tr).substr(1).replace(/[\.]?0*$/, '')
428+
);
427429
}
428430
return timeStr;
429431
}

test/jasmine/tests/lib_date_test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,5 +587,17 @@ describe('dates', function() {
587587

588588
});
589589

590+
it('should remove extra fractional second zeros', function() {
591+
expect(Lib.formatDate(0.1, '', 4)).toBe('00:00:00.0001\nJan 1, 1970');
592+
expect(Lib.formatDate(0.1, '', 3)).toBe('00:00:00\nJan 1, 1970');
593+
expect(Lib.formatDate(0.1, '', 3, 'coptic'))
594+
.toBe('00:00:00\nKoi 23, 1686');
595+
596+
// because the decimal point is explicitly part of the format
597+
// string here, we can't remove it OR the very first zero after it.
598+
expect(Lib.formatDate(0.1, '%S.%f')).toBe('00.0001');
599+
expect(Lib.formatDate(0.1, '%S.%3f')).toBe('00.0');
600+
});
601+
590602
});
591603
});

0 commit comments

Comments
 (0)