'NativeDateAdapter doesn't show month correctly after set locate
I extend NativeDateAdapter in angular material 13 and set locate to "fa-IR", after that the problem is, it doesn't show persian month from first day
it start show month from 12th day!! as show in this link
here is my adapter
import { NativeDateAdapter } from '@angular/material/core';
export class NativePersianDateAdapter extends NativeDateAdapter {
override parse(value: any): Date | null {
if (typeof value === 'string' && value.indexOf('/') > -1) {
const str = value.split('/');
const year = Number(str[2]);
const month = Number(str[1]) - 1;
const date = Number(str[0]);
return new Date(year, month, date);
}
const timestamp = typeof value === 'number' ? value : Date.parse(value);
return isNaN(timestamp) ? null : new Date(timestamp);
}
override getFirstDayOfWeek(): number {
return 6;
}
}
and I use it like this in app.module.ts
providers: [
{ provide: MAT_DATE_LOCALE, useValue: 'fa-IR' },
{ provide: MAT_MOMENT_DATE_ADAPTER_OPTIONS, useValue: { useUtc: true } },
{
provide: DateAdapter,
useClass: NativePersianDateAdapter,
deps: [MAT_DATE_LOCALE, MAT_MOMENT_DATE_ADAPTER_OPTIONS],
},
{ provide: MAT_DATE_FORMATS, useValue: PERSIAN_DATE_FORMATS },
],
Could any one help me?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
