Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(time-duration): getMostSignificantUnitOnlyWithoutApprox created to avoid approx #2586

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions projects/common/src/time/time-duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@
return new TimeDuration(amountForUnit, firstApplicableUnit);
}

public getMostSignificantUnitOnlyWithoutApprox(maxSupportedUnit?: TimeUnit): TimeDuration {

Check warning on line 77 in projects/common/src/time/time-duration.ts

View check run for this annotation

Codecov / codecov/patch

projects/common/src/time/time-duration.ts#L77

Added line #L77 was not covered by tests
let orderedUnits: ConvertibleTimeUnit[] = isNil(maxSupportedUnit)
? TimeDuration.TIME_UNITS
: TimeDuration.TIME_UNITS.slice(indexOf(TimeDuration.TIME_UNITS, maxSupportedUnit));

Check warning on line 80 in projects/common/src/time/time-duration.ts

View check run for this annotation

Codecov / codecov/patch

projects/common/src/time/time-duration.ts#L79-L80

Added lines #L79 - L80 were not covered by tests

let firstApplicableUnit = TimeUnit.Millisecond;
for (let unit of orderedUnits) {
const selectedUnitValue = this.getAmountForUnit(unit);

Check warning on line 84 in projects/common/src/time/time-duration.ts

View check run for this annotation

Codecov / codecov/patch

projects/common/src/time/time-duration.ts#L82-L84

Added lines #L82 - L84 were not covered by tests

if (selectedUnitValue >= 1 && selectedUnitValue - Math.floor(selectedUnitValue) === 0) {
firstApplicableUnit = unit;

Check warning on line 87 in projects/common/src/time/time-duration.ts

View check run for this annotation

Codecov / codecov/patch

projects/common/src/time/time-duration.ts#L87

Added line #L87 was not covered by tests

break;

Check warning on line 89 in projects/common/src/time/time-duration.ts

View check run for this annotation

Codecov / codecov/patch

projects/common/src/time/time-duration.ts#L89

Added line #L89 was not covered by tests
} else if (selectedUnitValue >= 1) {
firstApplicableUnit = unit;

Check warning on line 91 in projects/common/src/time/time-duration.ts

View check run for this annotation

Codecov / codecov/patch

projects/common/src/time/time-duration.ts#L91

Added line #L91 was not covered by tests
}
}
const amountForUnit = Math.floor(this.getAmountForUnit(firstApplicableUnit));

Check warning on line 94 in projects/common/src/time/time-duration.ts

View check run for this annotation

Codecov / codecov/patch

projects/common/src/time/time-duration.ts#L94

Added line #L94 was not covered by tests

return new TimeDuration(amountForUnit, firstApplicableUnit);

Check warning on line 96 in projects/common/src/time/time-duration.ts

View check run for this annotation

Codecov / codecov/patch

projects/common/src/time/time-duration.ts#L96

Added line #L96 was not covered by tests
}

public toString(): string {
return `${this.value}${this.unit}`;
}
Expand Down