diff --git a/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts b/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts index 9456ead9ff15..d871e35587d9 100644 --- a/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts +++ b/src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts @@ -99,6 +99,25 @@ describe('LuxonDateAdapter', () => { ]); }); + it('should get month names in a czech locale', () => { + adapter.setLocale('cs-CZ'); + + expect(adapter.getMonthNames('long')).toEqual([ + 'leden', + 'únor', + 'březen', + 'duben', + 'květen', + 'červen', + 'červenec', + 'srpen', + 'září', + 'říjen', + 'listopad', + 'prosinec', + ]); + }); + it('should get month names in a different locale', () => { adapter.setLocale('da-DK'); @@ -575,7 +594,7 @@ describe('LuxonDateAdapter with MAT_LUXON_DATE_ADAPTER_OPTIONS override', () => providers: [ { provide: MAT_LUXON_DATE_ADAPTER_OPTIONS, - useValue: {useUtc: true}, + useValue: {useUtc: true, firstDayOfWeek: 1}, }, ], }).compileComponents(); @@ -590,6 +609,10 @@ describe('LuxonDateAdapter with MAT_LUXON_DATE_ADAPTER_OPTIONS override', () => expect(adapter.createDate(2017, 0, 5).toISO()).toBe(DateTime.utc(2017, JAN, 5).toISO()); }); + it('should get first day of week', () => { + expect(adapter.getFirstDayOfWeek()).toBe(1); + }); + it('should create today in UTC', () => { const today = adapter.today(); expect(today.toISO()).toBe(today.toUTC().toISO()); diff --git a/src/material-luxon-adapter/adapter/luxon-date-adapter.ts b/src/material-luxon-adapter/adapter/luxon-date-adapter.ts index e61dd2f10916..17c894793e2b 100644 --- a/src/material-luxon-adapter/adapter/luxon-date-adapter.ts +++ b/src/material-luxon-adapter/adapter/luxon-date-adapter.ts @@ -22,6 +22,13 @@ export interface MatLuxonDateAdapterOptions { * {@default false} */ useUtc: boolean; + + /** + * Sets the first day of week. + * Changing this will change how Angular Material components like DatePicker shows start of week. + * {@default 0} + */ + firstDayOfWeek: number; } /** InjectionToken for LuxonDateAdapter to configure options. */ @@ -37,6 +44,7 @@ export const MAT_LUXON_DATE_ADAPTER_OPTIONS = new InjectionToken(length: number, valueFunction: (index: number) => T): T[] { @Injectable() export class LuxonDateAdapter extends DateAdapter { private _useUTC: boolean; + private _firstDayOfWeek: number; constructor( @Optional() @Inject(MAT_DATE_LOCALE) dateLocale: string, @@ -62,6 +71,7 @@ export class LuxonDateAdapter extends DateAdapter { ) { super(); this._useUTC = !!options?.useUtc; + this._firstDayOfWeek = options?.firstDayOfWeek || 0; this.setLocale(dateLocale || LuxonDateTime.local().locale); } @@ -109,8 +119,7 @@ export class LuxonDateAdapter extends DateAdapter { } getFirstDayOfWeek(): number { - // To customize the first day of the week, and can extend this adapter and override this method. - return 0; + return this._firstDayOfWeek; } getNumDaysInMonth(date: LuxonDateTime): number {