Skip to content
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