Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ability to override parse and format props in DateTimeInput component #4246

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/ra-ui-materialui/src/input/DateTimeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const dateTimeRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/;
*
* @param {Date | String} value date string or object
*/
const format = (value: string | Date) => {
const formatDateTime = (value: string | Date) => {
// null, undefined and empty string values should not go through convertDateToString
// otherwise, it returns undefined and will make the input an uncontrolled one.
if (value == null || value === '') {
Expand All @@ -58,14 +58,15 @@ const format = (value: string | Date) => {
* @param {String} value Date string, formatted as yyyy-MM-ddThh:mm
* @return {Date}
*/
const parse = (value: string) => new Date(value);
const parseDateTime = (value: string) => new Date(value);

/**
* Input component for entering a date and a time with timezone, using the browser locale
*/
export const DateTimeInput: FunctionComponent<
InputProps<TextFieldProps> & Omit<TextFieldProps, 'helperText' | 'label'>
> = ({
format = formatDateTime,
label,
helperText,
margin = 'dense',
Expand All @@ -75,6 +76,7 @@ export const DateTimeInput: FunctionComponent<
options,
source,
resource,
parse = parseDateTime,
validate,
variant = 'filled',
...rest
Expand Down