@@ -12,18 +12,26 @@ import { useEffect } from 'react';
1212// https://github.com/mui/material-ui/issues/30591#issuecomment-1377997824
1313class Adapter extends AdapterLuxon {
1414 public getWeekdays = ( ) => {
15- return [ 'S ' , 'M' , 'T ' , 'W' , 'T ' , 'F' , 'S ' ] ;
15+ return [ 'Su ' , 'M' , 'Tu ' , 'W' , 'Th ' , 'F' , 'Sa ' ] ;
1616 } ;
1717
1818 getWeekArray = ( date : DateTime ) => {
19- const { days } = date . endOf ( 'month' ) . endOf ( 'week' ) . diff ( date . startOf ( 'month' ) . startOf ( 'week' ) , 'days' ) . toObject ( ) ;
19+ date = date . setLocale ( 'en-US' ) ;
20+
21+ // Manually adjust the start and end of the week to begin on Sunday
22+ const startOfMonth = date . startOf ( 'month' ) ;
23+ const endOfMonth = date . endOf ( 'month' ) ;
24+ const startOfFirstWeek = startOfMonth . minus ( { days : startOfMonth . weekday % 7 } ) ;
25+ const endOfLastWeek = endOfMonth . plus ( { days : 6 - ( endOfMonth . weekday % 7 ) } ) ;
26+ const { days } = endOfLastWeek . diff ( startOfFirstWeek , 'days' ) . toObject ( ) ;
2027
2128 let weeks : DateTime [ ] [ ] = [ ] ;
2229 new Array ( Math . round ( days ?? 0 ) )
2330 . fill ( 0 )
2431 . map ( ( _ , i ) => i )
25- . map ( day => date . startOf ( 'month' ) . startOf ( 'week' ) . minus ( { days : 1 } ) . plus ( { days : day } ) )
32+ . map ( day => startOfFirstWeek . plus ( { days : day } ) )
2633 . forEach ( ( v , i ) => {
34+ console . log ( 'v' , v . toLocaleString ( ) , 'i' , i ) ;
2735 if ( i === 0 || ( i % 7 === 0 && i > 6 ) ) {
2836 weeks . push ( [ v ] ) ;
2937 return ;
0 commit comments