@@ -17,6 +17,8 @@ interface Props {
17
17
isRangePicker ?: boolean ;
18
18
startDate ?: DateTime | string ;
19
19
endDate ?: DateTime | string ;
20
+ // Optionally override the system locale for the dates users type
21
+ locale ?: string ;
20
22
filterType : AdminUIFilterType . DATE_TIME_RANGE | AdminUIFilterType . DATE_RANGE ;
21
23
fieldType : string ;
22
24
}
@@ -27,6 +29,7 @@ export const DatePicker = ({
27
29
isRangePicker = false ,
28
30
startDate,
29
31
endDate,
32
+ locale,
30
33
filterType,
31
34
fieldType,
32
35
} : Props ) => {
@@ -96,15 +99,17 @@ export const DatePicker = ({
96
99
: DateTime . fromISO ( inputEnd ) . startOf ( 'day' ) ;
97
100
98
101
// If that didn't work, attempt to parse from locale format
99
- const { locale } = Intl . DateTimeFormat ( ) . resolvedOptions ( ) ;
102
+ const resolvedOptions = Intl . DateTimeFormat ( ) . resolvedOptions ( ) ;
100
103
if ( ! parsedStart . isValid ) {
101
- parsedStart = DateTime . fromFormat ( inputStart , 'D' , { locale } ) ;
104
+ parsedStart = DateTime . fromFormat ( inputStart , 'D' , {
105
+ locale : locale ?? resolvedOptions . locale ,
106
+ } ) ;
102
107
if ( parsedStart . isValid ) setIsDateLocalFormat ( true ) ;
103
108
} else {
104
109
setIsDateLocalFormat ( false ) ;
105
110
}
106
111
if ( ! parsedEnd . isValid && inputEnd !== undefined ) {
107
- parsedEnd = DateTime . fromFormat ( inputEnd , 'D' , { locale } ) ;
112
+ parsedEnd = DateTime . fromFormat ( inputEnd , 'D' , { locale : locale ?? resolvedOptions . locale } ) ;
108
113
}
109
114
110
115
parsedStart = setTime ( parsedStart , luxonStartDate , parsedStart . startOf ( 'day' ) ) ?? parsedStart ;
0 commit comments