Browse Source

Bugfix: Localize month names in FIRE calculator

This fix localizes the retirement date display in the FIRE calculator using date-fns with the provided locale input, instead of relying on Angular DatePipe which depends on LOCALE_ID.

Fixes #6070
pull/6089/head
David Requeno 5 days ago
parent
commit
3f10a031a5
  1. 4
      libs/ui/src/lib/fire-calculator/fire-calculator.component.html
  2. 17
      libs/ui/src/lib/fire-calculator/fire-calculator.component.ts

4
libs/ui/src/lib/fire-calculator/fire-calculator.component.html

@ -31,9 +31,7 @@
<mat-form-field appearance="outline" class="w-100">
<mat-label i18n>Retirement Date</mat-label>
<div>
{{
calculatorForm.get('retirementDate')?.value | date: 'MMMM yyyy'
}}
{{ getFormattedRetirementDate() }}
</div>
<input
class="d-none"

17
libs/ui/src/lib/fire-calculator/fire-calculator.component.ts

@ -3,7 +3,7 @@ import {
transformTickToAbbreviation
} from '@ghostfolio/common/chart-helper';
import { primaryColorRgb } from '@ghostfolio/common/config';
import { getLocale } from '@ghostfolio/common/helper';
import { getDateFnsLocale, getLocale } from '@ghostfolio/common/helper';
import { FireCalculationCompleteEvent } from '@ghostfolio/common/interfaces';
import { ColorScheme } from '@ghostfolio/common/types';
@ -47,6 +47,7 @@ import {
add,
addDays,
addYears,
format,
getMonth,
setMonth,
setYear,
@ -235,6 +236,20 @@ export class GfFireCalculatorComponent implements OnChanges, OnDestroy {
this.calculatorForm.get('retirementDate').disable({ emitEvent: false });
}
public getFormattedRetirementDate(): string {
const retirementDate = this.calculatorForm.get('retirementDate')?.value;
if (!retirementDate) {
return '';
}
const dateFnsLocale = getDateFnsLocale(this.locale);
return format(retirementDate, 'MMMM yyyy', {
locale: dateFnsLocale
});
}
public setMonthAndYear(
normalizedMonthAndYear: Date,
datepicker: MatDatepicker<Date>

Loading…
Cancel
Save