Allow negative duration

Allow negative values for durationToString.
The use case is fairly constructed, but now logically correct
This commit is contained in:
Sean 2020-07-01 17:40:57 +02:00
parent fab51091b1
commit 23ee6a2951

View File

@ -88,10 +88,11 @@ export class DurationService {
* @returns a more human readable time representation
*/
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);
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 {
return '';
}