-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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 DateInput messes up dates in some timezones #10299
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than that it seems to work well! I emulated my position and locale to Honolulu, and saw no issues at all.
Also tested in Chrome and Firefox successfully. GJ!
@@ -202,38 +205,65 @@ export type DateInputProps = CommonInputProps & | |||
Omit<TextFieldProps, 'helperText' | 'label'>; | |||
|
|||
/** | |||
* Convert Date object to String | |||
* Convert Date object to String, ignoring the timezone. | |||
* | |||
* @param {Date} value value to convert | |||
* @returns {String} A standardized date (yyyy-MM-dd), to be passed to an <input type="date" /> | |||
*/ | |||
const convertDateToString = (value: Date) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still need this change for cases where the initial value is a non-standard date string (e.g. 02/02/2001)
## Problem The changes introduced in #10299 leads to a regression when the field value is an ISO string or date. The idea of that change was that if the value contains a date, react-admin should always display that date. This is often not what users want, because a date entered in a US browser than stored in GMT then displayed again will have shifted. Besides, this is not required to fix #10197. The fix in #10299 is the removal of the call to `parse` in `onChange` (in fact, `parse` used to be called twice). ## Solution Do not strip the timezone data, whether the field value is a string or a date.
## Problem The changes introduced in marmelab#10299 leads to a regression when the field value is an ISO string or date. The idea of that change was that if the value contains a date, react-admin should always display that date. This is often not what users want, because a date entered in a US browser than stored in GMT then displayed again will have shifted. Besides, this is not required to fix marmelab#10197. The fix in marmelab#10299 is the removal of the call to `parse` in `onChange` (in fact, `parse` used to be called twice). ## Solution Do not strip the timezone data, whether the field value is a string or a date.
Problem
Fixes #10197
Solution
We were trying to convert the input value into a
Date
. However, when passing a partial date (such as the html input valueyyyy-MM-dd
) toDate
, it assumes the UTC timezone. When stringified again, this UTC date might be different than the one entered by users because of their timezone.How To Test
Additional Checks
master
for a bugfix, ornext
for a feature