Merge pull request #5447 from tsiegleauq/allow-negative-duration

Allow negative duration
This commit is contained in:
Finn Stutzenstein 2020-07-02 11:43:25 +02:00 committed by GitHub
commit cb190331f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,10 +88,11 @@ export class DurationService {
* @returns a more human readable time representation * @returns a more human readable time representation
*/ */
public durationToString(duration: number, suffix: 'h' | 'm'): string { public durationToString(duration: number, suffix: 'h' | 'm'): string {
const major = Math.floor(duration / 60); const major = duration < 0 ? Math.ceil(duration / 60) : Math.floor(duration / 60);
const minor = `0${duration % 60}`.slice(-2); const minor = `0${duration % 60}`.slice(-2);
if (!isNaN(+major) && !isNaN(+minor)) { if (!isNaN(+major) && !isNaN(+minor)) {
return `${major}:${minor} ${suffix}`; // converting the number '-0' to string results in '0'
return `${major === -0 ? '-' + major : major}:${minor} ${suffix}`;
} else { } else {
return ''; return '';
} }