changed duration format to also represent days

This commit is contained in:
bgildson
2020-10-29 08:46:54 -03:00
parent 72918a62d8
commit bcf7332675
2 changed files with 15 additions and 8 deletions

View File

@@ -96,19 +96,26 @@ export function generateUsername() {
return `User ${(Math.floor(Math.random() * 42) + 1)}`;
}
export function secondsToHMMSS(seconds = 0) {
export function padLeft(text, pad, size) {
return String(pad.repeat(size) + text).slice(-size);
}
export function parseSecondsToDurationString(seconds = 0) {
const finiteSeconds = Number.isFinite(+seconds) ? Math.abs(seconds) : 0;
const hours = Math.floor(finiteSeconds / 3600);
const hoursString = hours ? `${hours}:` : '';
const days = Math.floor(finiteSeconds / 86400);
const daysString = days > 0 ? `${days} day${days > 1 ? 's' : ''} ` : '';
const hours = Math.floor((finiteSeconds / 3600) % 24);
const hoursString = hours || days ? padLeft(`${hours}:`, '0', 3) : '';
const mins = Math.floor((finiteSeconds / 60) % 60);
const minString = mins < 10 ? `0${mins}:` : `${mins}:`;
const minString = padLeft(`${mins}:`, '0', 3);
const secs = Math.floor(finiteSeconds % 60);
const secsString = secs < 10 ? `0${secs}` : `${secs}`;
const secsString = padLeft(`${secs}`, '0', 2);
return hoursString + minString + secsString;
return daysString + hoursString + minString + secsString;
}
export function setVHvar() {