File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
src/material/core/datetime Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,24 @@ export class NativeDateAdapter extends DateAdapter<Date> {
89
89
}
90
90
91
91
getFirstDayOfWeek ( ) : number {
92
- // We can't tell using native JS Date what the first day of the week is, we default to Sunday.
92
+ // At the time of writing `Intl.Locale` isn't available
93
+ // in the internal types so we need to cast to `any`.
94
+ if ( typeof Intl !== 'undefined' && ( Intl as any ) . Locale ) {
95
+ const locale = new ( Intl as any ) . Locale ( this . locale ) as {
96
+ getWeekInfo ?: ( ) => { firstDay : number } ;
97
+ weekInfo ?: { firstDay : number } ;
98
+ } ;
99
+
100
+ // Some browsers implement a `getWeekInfo` method while others have a `weekInfo` getter.
101
+ // Note that this isn't supported in all browsers so we need to null check it.
102
+ const firstDay = ( locale . getWeekInfo ?.( ) || locale . weekInfo ) ?. firstDay ?? 0 ;
103
+
104
+ // `weekInfo.firstDay` is a number between 1 and 7 where, starting from Monday,
105
+ // whereas our representation is 0 to 6 where 0 is Sunday so we need to normalize it.
106
+ return firstDay === 7 ? 0 : firstDay ;
107
+ }
108
+
109
+ // Default to Sunday if the browser doesn't provide the week information.
93
110
return 0 ;
94
111
}
95
112
You can’t perform that action at this time.
0 commit comments