Skip to content

Commit a52da04

Browse files
authored
feat(material-luxon-adapter): add option to set first day of week (#24027)
* feat(material-luxon-adapter): add option to set first day of week Add firstDayOfWeek option to be able to change first day of week behaviour through MAT_LUXON_DATE_ADAPTER_OPTIONS * test(material-luxon-adapter): Added one more test to trigger CI
1 parent 1ca8a78 commit a52da04

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ describe('LuxonDateAdapter', () => {
9999
]);
100100
});
101101

102+
it('should get month names in a czech locale', () => {
103+
adapter.setLocale('cs-CZ');
104+
105+
expect(adapter.getMonthNames('long')).toEqual([
106+
'leden',
107+
'únor',
108+
'březen',
109+
'duben',
110+
'květen',
111+
'červen',
112+
'červenec',
113+
'srpen',
114+
'září',
115+
'říjen',
116+
'listopad',
117+
'prosinec',
118+
]);
119+
});
120+
102121
it('should get month names in a different locale', () => {
103122
adapter.setLocale('da-DK');
104123

@@ -575,7 +594,7 @@ describe('LuxonDateAdapter with MAT_LUXON_DATE_ADAPTER_OPTIONS override', () =>
575594
providers: [
576595
{
577596
provide: MAT_LUXON_DATE_ADAPTER_OPTIONS,
578-
useValue: {useUtc: true},
597+
useValue: {useUtc: true, firstDayOfWeek: 1},
579598
},
580599
],
581600
}).compileComponents();
@@ -590,6 +609,10 @@ describe('LuxonDateAdapter with MAT_LUXON_DATE_ADAPTER_OPTIONS override', () =>
590609
expect(adapter.createDate(2017, 0, 5).toISO()).toBe(DateTime.utc(2017, JAN, 5).toISO());
591610
});
592611

612+
it('should get first day of week', () => {
613+
expect(adapter.getFirstDayOfWeek()).toBe(1);
614+
});
615+
593616
it('should create today in UTC', () => {
594617
const today = adapter.today();
595618
expect(today.toISO()).toBe(today.toUTC().toISO());

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export interface MatLuxonDateAdapterOptions {
2222
* {@default false}
2323
*/
2424
useUtc: boolean;
25+
26+
/**
27+
* Sets the first day of week.
28+
* Changing this will change how Angular Material components like DatePicker shows start of week.
29+
* {@default 0}
30+
*/
31+
firstDayOfWeek: number;
2532
}
2633

2734
/** InjectionToken for LuxonDateAdapter to configure options. */
@@ -37,6 +44,7 @@ export const MAT_LUXON_DATE_ADAPTER_OPTIONS = new InjectionToken<MatLuxonDateAda
3744
export function MAT_LUXON_DATE_ADAPTER_OPTIONS_FACTORY(): MatLuxonDateAdapterOptions {
3845
return {
3946
useUtc: false,
47+
firstDayOfWeek: 0,
4048
};
4149
}
4250

@@ -53,6 +61,7 @@ function range<T>(length: number, valueFunction: (index: number) => T): T[] {
5361
@Injectable()
5462
export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
5563
private _useUTC: boolean;
64+
private _firstDayOfWeek: number;
5665

5766
constructor(
5867
@Optional() @Inject(MAT_DATE_LOCALE) dateLocale: string,
@@ -62,6 +71,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
6271
) {
6372
super();
6473
this._useUTC = !!options?.useUtc;
74+
this._firstDayOfWeek = options?.firstDayOfWeek || 0;
6575
this.setLocale(dateLocale || LuxonDateTime.local().locale);
6676
}
6777

@@ -109,8 +119,7 @@ export class LuxonDateAdapter extends DateAdapter<LuxonDateTime> {
109119
}
110120

111121
getFirstDayOfWeek(): number {
112-
// To customize the first day of the week, and can extend this adapter and override this method.
113-
return 0;
122+
return this._firstDayOfWeek;
114123
}
115124

116125
getNumDaysInMonth(date: LuxonDateTime): number {

0 commit comments

Comments
 (0)