Fix time zone issue when displaying active month in date time picker. (6.2)
#23987
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: This is a backport of #23918 to
6.2.Description
Motivation and Context
As described in #22273 the active month in date time pickers can be wrong. This can happen for dates like
2025-10-01when the browser time zone is UTC - X.This PR fixes the problem by using moment to provide a JavaScript date in the correct format.
The date time picker only gets dates in the following format
2025-10-01.toDateObject('2025-10-01').toDate()andnew Date('2025-10-01'), treat this as UTC midnight. With a timezone likeAmerica/Los_Angeles(UTC-7), this generates the following JavaScript dateTue Sep 30 2025 17:00:00 GMT-0700 (Pacific Daylight Time).By using
moment(selectedDate, 'YYYY-MM-DD').toDate()it generates a JavaScript DateOct 01 2025 00:00:00 GMT-0700 (Pacific Daylight Time), which has the same day and month like the provided date2025-10-01.Ideally we avoid using moment directly, but in this case it makes it easy to backport the fix. In future versions we can avoid this by upgrading the
react-day-picker#23857. The newer versions have improved time zone support.Fixes #22273