Skip to content

fix(material-luxon-adapter): infer first day of week from locale #30285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ describe('LuxonDateAdapter', () => {
});

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

it('should create Luxon date', () => {
Expand Down
9 changes: 4 additions & 5 deletions src/material-luxon-adapter/adapter/luxon-date-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface MatLuxonDateAdapterOptions {
* Sets the first day of week.
* Changing this will change how Angular Material components like DatePicker shows start of week.
*/
firstDayOfWeek: number;
firstDayOfWeek?: number;

/**
* Sets the output Calendar.
Expand All @@ -49,7 +49,6 @@ export const MAT_LUXON_DATE_ADAPTER_OPTIONS = new InjectionToken<MatLuxonDateAda
export function MAT_LUXON_DATE_ADAPTER_OPTIONS_FACTORY(): MatLuxonDateAdapterOptions {
return {
useUtc: false,
firstDayOfWeek: 0,
defaultOutputCalendar: 'gregory',
};
}
Expand All @@ -67,7 +66,7 @@ function range<T>(length: number, valueFunction: (index: number) => T): T[] {
@Injectable()
export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
private _useUTC: boolean;
private _firstDayOfWeek: number;
private _firstDayOfWeek: number | undefined;
private _defaultOutputCalendar: LuxonCalendarSystem;

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

this._useUTC = !!options?.useUtc;
this._firstDayOfWeek = options?.firstDayOfWeek || 0;
this._firstDayOfWeek = options?.firstDayOfWeek;
this._defaultOutputCalendar = options?.defaultOutputCalendar || 'gregory';
this.setLocale(dateLocale || LuxonDateTime.local().locale);
}
Expand Down Expand Up @@ -134,7 +133,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
}

getFirstDayOfWeek(): number {
return this._firstDayOfWeek;
return this._firstDayOfWeek ?? LuxonInfo.getStartOfWeek({locale: this.locale});
}

getNumDaysInMonth(date: LuxonDateTime): number {
Expand Down
Loading