@@ -9,6 +9,38 @@ import { InputText } from '../InputText/InputText';
99import { InputProps } from '../InputBase' ;
1010import { useEffect } from 'react' ;
1111
12+ // https://github.com/mui/material-ui/issues/30591#issuecomment-1377997824
13+ class Adapter extends AdapterLuxon {
14+ public getWeekdays = ( ) => {
15+ return [ 'S' , 'M' , 'T' , 'W' , 'T' , 'F' , 'S' ] ;
16+ } ;
17+
18+ getWeekArray = ( date : DateTime ) => {
19+ const { days } = date . endOf ( 'month' ) . endOf ( 'week' ) . diff ( date . startOf ( 'month' ) . startOf ( 'week' ) , 'days' ) . toObject ( ) ;
20+
21+ let weeks : DateTime [ ] [ ] = [ ] ;
22+ new Array ( Math . round ( days ?? 0 ) )
23+ . fill ( 0 )
24+ . map ( ( _ , i ) => i )
25+ . map ( day => date . startOf ( 'month' ) . startOf ( 'week' ) . minus ( { days : 1 } ) . plus ( { days : day } ) )
26+ . forEach ( ( v , i ) => {
27+ if ( i === 0 || ( i % 7 === 0 && i > 6 ) ) {
28+ weeks . push ( [ v ] ) ;
29+ return ;
30+ }
31+
32+ weeks [ weeks . length - 1 ] . push ( v ) ;
33+ } ) ;
34+
35+ weeks = weeks . filter ( week => {
36+ // do not allow weeks with start or end outside of current month
37+ return week [ 0 ] . hasSame ( date , 'month' ) || week [ week . length - 1 ] . hasSame ( date , 'month' ) ;
38+ } ) ;
39+
40+ return weeks ;
41+ } ;
42+ }
43+
1244export type InputDateProps = Omit < InputProps , 'onChange' > & {
1345 value ?: Date | string ;
1446 onChange ?: ( date : Date | string | null ) => void ;
@@ -44,7 +76,7 @@ export const InputDate: FC<InputDateProps> = ({
4476 } , [ fieldValue ] ) ;
4577
4678 return (
47- < LocalizationProvider dateAdapter = { AdapterLuxon } >
79+ < LocalizationProvider dateAdapter = { Adapter } >
4880 < DatePicker
4981 { ...datePickerProps }
5082 label = { label }
0 commit comments