Skip to content

Commit

Permalink
improves fix to be applied only for ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Balduini authored and Arthur Balduini committed Aug 26, 2024
1 parent b6769ec commit 0dbc59a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions packages/x-date-pickers/src/internals/utils/date-time-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@ export const resolveDateTimeFormat = <TDate extends PickerValidDate>(
views,
format,
...other
}: { format?: string; views: readonly DateOrTimeViewWithMeridiem[]; ampm: boolean },
}: {
format?: string;
views: readonly DateOrTimeViewWithMeridiem[];
ampm: boolean;
value: TDate | TDate[];
},
) => {
if (format) {
return format;
}

const { value } = other;

const dateViews: DateView[] = [];
const timeViews: TimeView[] = [];

Expand All @@ -44,7 +51,9 @@ export const resolveDateTimeFormat = <TDate extends PickerValidDate>(
}

const timeFormat = resolveTimeFormat(utils, { views: timeViews, ...other });
const dateFormat = resolveDateFormat(utils, { views: dateViews, ...other }, false);
const dateFormat = Array.isArray(value)
? utils.formats.keyboardDate // default for DateTimeRanePicker
: resolveDateFormat(utils, { views: dateViews, ...other }, false);

return `${dateFormat} ${timeFormat}`;
};
Expand Down
2 changes: 1 addition & 1 deletion packages/x-date-pickers/src/internals/utils/date-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const resolveDateFormat = <TDate extends PickerValidDate>(
}

if (areViewsEqual(views, ['day'])) {
return formats.keyboardDate;
return formats.dayOfMonth;
}

if (areViewsEqual(views, ['month', 'year'])) {
Expand Down

0 comments on commit 0dbc59a

Please sign in to comment.