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 @@ -102,7 +102,24 @@ export class NativeDateAdapter extends DateAdapter<Date> {
102102 }
103103
104104 getFirstDayOfWeek ( ) : number {
105- // We can't tell using native JS Date what the first day of the week is, we default to Sunday.
105+ // At the time of writing `Intl.Locale` isn't available
106+ // in the internal types so we need to cast to `any`.
107+ if ( typeof Intl !== 'undefined' && ( Intl as any ) . Locale ) {
108+ const locale = new ( Intl as any ) . Locale ( this . locale ) as {
109+ getWeekInfo ?: ( ) => { firstDay : number } ;
110+ weekInfo ?: { firstDay : number } ;
111+ } ;
112+
113+ // Some browsers implement a `getWeekInfo` method while others have a `weekInfo` getter.
114+ // Note that this isn't supported in all browsers so we need to null check it.
115+ const firstDay = ( locale . getWeekInfo ?.( ) || locale . weekInfo ) ?. firstDay ?? 0 ;
116+
117+ // `weekInfo.firstDay` is a number between 1 and 7 where, starting from Monday,
118+ // whereas our representation is 0 to 6 where 0 is Sunday so we need to normalize it.
119+ return firstDay === 7 ? 0 : firstDay ;
120+ }
121+
122+ // Default to Sunday if the browser doesn't provide the week information.
106123 return 0 ;
107124 }
108125
You can’t perform that action at this time.
0 commit comments