1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-14 10:00:53 +00:00
FrankerFaceZ/src/utilities/time.js

24 lines
647 B
JavaScript
Raw Normal View History

2017-11-13 01:23:39 -05:00
'use strict';
export function duration_to_string(elapsed, separate_days, days_only, no_hours, no_seconds) {
const seconds = elapsed % 60;
let minutes = Math.floor(elapsed / 60),
hours = Math.floor(minutes / 60),
days = '';
minutes = minutes % 60;
if ( separate_days ) {
days = Math.floor(hours / 24);
hours = hours % 24;
if ( days_only && days > 0 )
return `${days} days`;
days = days > 0 ? `${days} days, ` : '';
}
return `${days}${
(!no_hours || days || hours) ? `${days && hours < 10 ? '0' : ''}${hours}:` : ''
}${minutes < 10 ? '0' : ''}${minutes}${
no_seconds ? '' : `:${seconds < 10 ? '0' : ''}${seconds}`}`;
}