Making sure seconds are padded when they add up to zero
This commit is contained in:
@@ -28,14 +28,21 @@ export function getSecondsAsHHMMSS(totalSeconds: Number) {
|
||||
const dateObj = new Date(totalSeconds * 1000);
|
||||
const minutes = dateObj.getUTCMinutes();
|
||||
// make sure we add any possible decimal value
|
||||
let seconds = (dateObj.getSeconds() + (totalSeconds % 1.0));
|
||||
if (countDecimals(seconds) > 2) {
|
||||
seconds = seconds.toFixed(2);
|
||||
const seconds = dateObj.getSeconds();
|
||||
const ms = totalSeconds % 1.0;
|
||||
let msStr = '';
|
||||
if (countDecimals(ms) > 0) {
|
||||
if (countDecimals(ms) > 2) {
|
||||
msStr = ms.toFixed(2);
|
||||
} else {
|
||||
msStr = String(ms);
|
||||
}
|
||||
msStr = '.' + msStr.split('.')[1];
|
||||
}
|
||||
|
||||
return hours.toString().padStart(2, '0') + ':' +
|
||||
minutes.toString().padStart(2, '0') + ':' +
|
||||
seconds.toString().padStart(2, '0');
|
||||
seconds.toString().padStart(2, '0') + msStr;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -224,9 +224,9 @@ describe('Utility Tests', () => {
|
||||
describe('addTwoDurations()', () => {
|
||||
it('P1H5M30.5S plus PT15M10S equals P1H20M40.5S', () => {
|
||||
expect(
|
||||
Utilities.addTwoDurations('PT1H5M30.5S', 'PT15M10S',
|
||||
Utilities.addTwoDurations('PT1H5M30.5S', 'PT15M30S',
|
||||
scorm2004_regex.CMITimespan),
|
||||
).to.equal('PT1H20M40.5S');
|
||||
).to.equal('PT1H21M0.5S');
|
||||
});
|
||||
it('P1Y364D plus P2DT1H45M52S equals P732DT1H45M52S', () => {
|
||||
expect(
|
||||
@@ -251,9 +251,9 @@ describe('Utility Tests', () => {
|
||||
describe('addHHMMSSTimeStrings()', () => {
|
||||
it('01:05:30.5 plus 00:15:10 equals 01:20:40.5', () => {
|
||||
expect(
|
||||
Utilities.addHHMMSSTimeStrings('01:05:30.5', '00:15:10',
|
||||
Utilities.addHHMMSSTimeStrings('01:05:30.5', '00:15:30',
|
||||
scorm12_regex.CMITimespan),
|
||||
).to.equal('01:20:40.5');
|
||||
).to.equal('01:21:00.5');
|
||||
});
|
||||
it('17496:00:00 plus 49:35:52 equals 17545:35:52', () => {
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user