Lots of Bugfixes (#3308)
This commit is contained in:
parent
ed7e9d4a6e
commit
fc269d3dd2
36 changed files with 331 additions and 588 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import {TranslocoService} from "@jsverse/transloco";
|
||||
import {HourEstimateRange} from "../_models/series-detail/hour-estimate-range";
|
||||
import {DecimalPipe} from "@angular/common";
|
||||
|
||||
@Pipe({
|
||||
name: 'readTimeLeft',
|
||||
|
|
@ -8,9 +9,31 @@ import {HourEstimateRange} from "../_models/series-detail/hour-estimate-range";
|
|||
})
|
||||
export class ReadTimeLeftPipe implements PipeTransform {
|
||||
|
||||
constructor(private translocoService: TranslocoService) {}
|
||||
constructor(private readonly translocoService: TranslocoService) {}
|
||||
|
||||
transform(readingTimeLeft: HourEstimateRange): string {
|
||||
return `~${readingTimeLeft.avgHours} ${readingTimeLeft.avgHours > 1 ? this.translocoService.translate('read-time-pipe.hours') : this.translocoService.translate('read-time-pipe.hour')}`;
|
||||
const hoursLabel = readingTimeLeft.avgHours > 1
|
||||
? this.translocoService.translate('read-time-pipe.hours')
|
||||
: this.translocoService.translate('read-time-pipe.hour');
|
||||
|
||||
const formattedHours = this.customRound(readingTimeLeft.avgHours);
|
||||
|
||||
return `~${formattedHours} ${hoursLabel}`;
|
||||
}
|
||||
|
||||
private customRound(value: number): string {
|
||||
const integerPart = Math.floor(value);
|
||||
const decimalPart = value - integerPart;
|
||||
|
||||
if (decimalPart < 0.5) {
|
||||
// Round down to the nearest whole number
|
||||
return integerPart.toString();
|
||||
} else if (decimalPart >= 0.5 && decimalPart < 0.9) {
|
||||
// Return with 1 decimal place
|
||||
return value.toFixed(1);
|
||||
} else {
|
||||
// Round up to the nearest whole number
|
||||
return Math.ceil(value).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue