fix(common/Time): fix humanizeDuration for duration > 1 year
This commit is contained in:
parent
cb5001ce6e
commit
0c4349fac3
@ -67,7 +67,7 @@ export class Time {
|
||||
public static humanizeDuration(
|
||||
duration: number,
|
||||
short: boolean = false,
|
||||
skipOneUnitNumber: boolean = false,
|
||||
skipNumberTextPartWhenSingular: boolean = false,
|
||||
units: TimeUnit[] = [
|
||||
this.UNITS.SECOND,
|
||||
this.UNITS.MINUTE,
|
||||
@ -77,13 +77,13 @@ export class Time {
|
||||
this.UNITS.YEAR,
|
||||
],
|
||||
): string {
|
||||
for (let i = units.length - 1; i > 0; i--) {
|
||||
if (duration >= units[i - 1].milliseconds && duration < units[i].milliseconds) {
|
||||
const amount = Math.floor(duration / units[i - 1].milliseconds);
|
||||
const unit = short ?
|
||||
units[i - 1].shortName :
|
||||
' ' + units[i - 1].longName + (amount > 1 ? 's' : '');
|
||||
return (amount > 1 || !skipOneUnitNumber ? amount : '') + unit;
|
||||
for (const unit of units.reverse()) {
|
||||
if (duration >= unit.milliseconds) {
|
||||
const amount = Math.floor(duration / unit.milliseconds);
|
||||
const unitTextPart = short ?
|
||||
unit.shortName :
|
||||
' ' + unit.longName + (amount > 1 ? 's' : '');
|
||||
return (amount > 1 || !skipNumberTextPartWhenSingular ? amount : '') + unitTextPart;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user