Skip to content

Commit d55dbbd

Browse files
Merge pull request #1769 from exogee-technology/feature/locale-for-date-inputs
Internal Feature / Locale Option on Date Inputs
2 parents bcf42f8 + 87488ba commit d55dbbd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/packages/admin-ui-components/src/date-picker/component.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ interface Props {
1717
isRangePicker?: boolean;
1818
startDate?: DateTime | string;
1919
endDate?: DateTime | string;
20+
// Optionally override the system locale for the dates users type
21+
locale?: string;
2022
filterType: AdminUIFilterType.DATE_TIME_RANGE | AdminUIFilterType.DATE_RANGE;
2123
fieldType: string;
2224
}
@@ -27,6 +29,7 @@ export const DatePicker = ({
2729
isRangePicker = false,
2830
startDate,
2931
endDate,
32+
locale,
3033
filterType,
3134
fieldType,
3235
}: Props) => {
@@ -96,15 +99,17 @@ export const DatePicker = ({
9699
: DateTime.fromISO(inputEnd).startOf('day');
97100

98101
// If that didn't work, attempt to parse from locale format
99-
const { locale } = Intl.DateTimeFormat().resolvedOptions();
102+
const resolvedOptions = Intl.DateTimeFormat().resolvedOptions();
100103
if (!parsedStart.isValid) {
101-
parsedStart = DateTime.fromFormat(inputStart, 'D', { locale });
104+
parsedStart = DateTime.fromFormat(inputStart, 'D', {
105+
locale: locale ?? resolvedOptions.locale,
106+
});
102107
if (parsedStart.isValid) setIsDateLocalFormat(true);
103108
} else {
104109
setIsDateLocalFormat(false);
105110
}
106111
if (!parsedEnd.isValid && inputEnd !== undefined) {
107-
parsedEnd = DateTime.fromFormat(inputEnd, 'D', { locale });
112+
parsedEnd = DateTime.fromFormat(inputEnd, 'D', { locale: locale ?? resolvedOptions.locale });
108113
}
109114

110115
parsedStart = setTime(parsedStart, luxonStartDate, parsedStart.startOf('day')) ?? parsedStart;

0 commit comments

Comments
 (0)