Skip to content

Commit e52a369

Browse files
committedJan 9, 2025
fix(material-luxon-adapter): infer first day of week from locale (#30285)
Fixes that the Luxon date adapter was hardcoding the first day of the week to Sunday, unless it's provided through DI. Fixes #30278. (cherry picked from commit 659e5d4)
1 parent 56f2aa4 commit e52a369

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed
 

‎src/material-luxon-adapter/adapter/luxon-date-adapter.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ describe('LuxonDateAdapter', () => {
258258
});
259259

260260
it('should get first day of week', () => {
261-
expect(adapter.getFirstDayOfWeek()).toBe(0);
261+
adapter.setLocale('bg-BG');
262+
expect(adapter.getFirstDayOfWeek()).toBe(1);
262263
});
263264

264265
it('should create Luxon date', () => {

‎src/material-luxon-adapter/adapter/luxon-date-adapter.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface MatLuxonDateAdapterOptions {
2727
* Sets the first day of week.
2828
* Changing this will change how Angular Material components like DatePicker shows start of week.
2929
*/
30-
firstDayOfWeek: number;
30+
firstDayOfWeek?: number;
3131

3232
/**
3333
* Sets the output Calendar.
@@ -49,7 +49,6 @@ export const MAT_LUXON_DATE_ADAPTER_OPTIONS = new InjectionToken<MatLuxonDateAda
4949
export function MAT_LUXON_DATE_ADAPTER_OPTIONS_FACTORY(): MatLuxonDateAdapterOptions {
5050
return {
5151
useUtc: false,
52-
firstDayOfWeek: 0,
5352
defaultOutputCalendar: 'gregory',
5453
};
5554
}
@@ -67,7 +66,7 @@ function range<T>(length: number, valueFunction: (index: number) => T): T[] {
6766
@Injectable()
6867
export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
6968
private _useUTC: boolean;
70-
private _firstDayOfWeek: number;
69+
private _firstDayOfWeek: number | undefined;
7170
private _defaultOutputCalendar: LuxonCalendarSystem;
7271

7372
constructor(...args: unknown[]);
@@ -81,7 +80,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
8180
});
8281

8382
this._useUTC = !!options?.useUtc;
84-
this._firstDayOfWeek = options?.firstDayOfWeek || 0;
83+
this._firstDayOfWeek = options?.firstDayOfWeek;
8584
this._defaultOutputCalendar = options?.defaultOutputCalendar || 'gregory';
8685
this.setLocale(dateLocale || LuxonDateTime.local().locale);
8786
}
@@ -134,7 +133,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
134133
}
135134

136135
getFirstDayOfWeek(): number {
137-
return this._firstDayOfWeek;
136+
return this._firstDayOfWeek ?? LuxonInfo.getStartOfWeek({locale: this.locale});
138137
}
139138

140139
getNumDaysInMonth(date: LuxonDateTime): number {

0 commit comments

Comments
 (0)