Lots of Bugfixes (#3308)

This commit is contained in:
Joe Milazzo 2024-10-25 09:22:12 -07:00 committed by GitHub
parent ed7e9d4a6e
commit fc269d3dd2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 331 additions and 588 deletions

View file

@ -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();
}
}
}